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!

range("A1").formula not working in VBA code

Status
Not open for further replies.

Chrissirhc

Programmer
May 20, 2000
926
GB
Hi,

Why can I not use the below code:

counter = argA + argB

range("A1").formula = "=if(autorun, " & counter & ", Hello)"

I get the "application-definted or object-defined error" debug window.

But I can do

range("A1").formula = "=if(autorun, 55 , Hello)"

fine.

Why can't I do the first thing I am trying?

Thanks,

Chris

 
What is the value of counter when in debug mode after the error raised ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 

You're not telling us enough. This does not generate any error for me:
Code:
Sub test()
counter = argA + argB

Range("A1").Formula = "=if(autorun, " & counter & ", Hello)"

End Sub
 
I've changed the code to make it work...

formulaString = "=if(autorun, """ & counter & """, """")"
range("A1").formula = formulaString

Thanks for the responses though...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top