I'm having a challenge with writing a formula to a cell via code:
Example:
Sheets("Sheet1").Range("A1").Formula = "="Some text here: " & Sheet2!C2"
I'm receiving a compile error: syntax error
I have tried adding additional quote marks to the end of the statement but to no avail.
Thanks for taking a look,
John
VBA Formula Assistance
-
- GoldLounger
- Posts: 2631
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
VBA Formula Assistance
Regards,
John
John
-
- Administrator
- Posts: 78512
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: VBA Formula Assistance
It should be
Sheets("Sheet1").Range("A1").Formula = "=Some text here: " & Sheet2!C2
Sheets("Sheet1").Range("A1").Formula = "=Some text here: " & Sheet2!C2
Best wishes,
Hans
Hans
-
- GoldLounger
- Posts: 2631
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
Re: VBA Formula Assistance
Hans,
I'm now coming up with another error:
run-time error 424: object required
Regards,
John
I'm now coming up with another error:
run-time error 424: object required
Regards,
John
Regards,
John
John
-
- Administrator
- Posts: 78512
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: VBA Formula Assistance
Sorry, my mistake. I didn't notice that you hadn't used VBA for the last part.
Sheets("Sheet1").Range("A1").Formula = "=Some text here: " & Worksheets("Sheet2").Range("C2")
Sheets("Sheet1").Range("A1").Formula = "=Some text here: " & Worksheets("Sheet2").Range("C2")
Best wishes,
Hans
Hans
-
- GoldLounger
- Posts: 2631
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
-
- 3StarLounger
- Posts: 233
- Joined: 10 Feb 2010, 19:17
Re: VBA Formula Assistance
Me too.
I was going to reply but could not get it to work, so I went to break.
On the way there I remembered -All you have to do is Record a macro and perform the steps. Then look at the macro and tweak.
(Just in case Hans is not avaiable).
I was going to reply but could not get it to work, so I went to break.
On the way there I remembered -All you have to do is Record a macro and perform the steps. Then look at the macro and tweak.
(Just in case Hans is not avaiable).
Chuck Reimer
(I'm from the Government and I'm here to help) ;-)
(I'm from the Government and I'm here to help) ;-)
-
- 5StarLounger
- Posts: 817
- Joined: 24 Jan 2010, 15:56
Re: VBA Formula Assistance
I would have thought:
Sheets("Sheet1").Range("A1").Formula = "=""Some text here: ""&Sheet2!C2"
Sheets("Sheet1").Range("A1").Formula = "=""Some text here: ""&Sheet2!C2"
Regards,
Rory
Rory
-
- Administrator
- Posts: 78512
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands