Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Placing a formula in VBA

Status
Not open for further replies.

OomJan

Technical User
Feb 16, 2005
4
NL
I'm trying to let a piece of code to place a formula in a cell.

I've tried someting like this:
Formule_String = "(IF(Sheet1!C10>"";"SSCC = "&Sheet2!C10;""))"

Sheets("Sheet1").Range("A31").formula = Formule_String

It goes wrong with all the """'s How can I fix it?
 
Hi OomJan,

What is the actual formula meant to be?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Code:
' Make sure you're in the correct 
Dim obj As Object
Set obj = Activeworkbook  workbook

' Make sure you're on the correct sheet
Worksheets("Sheet1").Select

' Add sample Values for this example
ActiveSheet.Range("B2").Value = 2
ActiveSheet.Range("C2").Value = 3

' Insert a formula
ActiveSheet.Range("D2").Formula = "=b2+c2"

I hope this helps !
 

Sorry, I goofed the 1st comment line ...

Code:
' Make sure you're in the correct workbook
Dim obj As Object
Set obj = Activeworkbook 

' Make sure you're on the correct sheet
Worksheets("Sheet1").Select

' Add sample Values for this example
ActiveSheet.Range("B2").Value = 2
ActiveSheet.Range("C2").Value = 3

' Insert a formula
ActiveSheet.Range("D2").Formula = "=b2+c2"
 
Formule_String = "=IF(Sheet1!C10<>"""",CONCATENATE(""SSCC = "",Sheet2!C10),"""")"

Sheets("Sheet1").Range("A1").Formula = Formule_String
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top