Can't compile text with "" as part of the text.

pingme89

Board Regular
Joined
Jan 23, 2014
Messages
149
I am using VBA to put a formula into a cell.

The formula I want to put is based on a counter, i.

The desired formula would be: =IF($B384 > 0, $H384, "") where the row number is derived by a counter.

My code is:

Lastentry = Lastentry - 1
For i = Lastentry To Lastentry + Addrow


Worksheets(2).Cells(Lastentry, "I") = "=" & "B" & Lastentry & " * " & "G" & Lastentry
Worksheets(2).Cells(Lastentry, "O") = "=" & "$B" & Lastentry & " * " & "$F" & Lastentry
Worksheets(2).Cells(Lastentry, "P") = "=IF($B" & Lastentry & " > " & 0 & ", $H" & Lastentry & ","")"
Lastentry = Lastentry + 1
Next i


However, the formula never comes out right. the last "" between the comma and the right bracket never comes out properly.
The result I get is: =IF($B389 > 0, $H389,")

What can I do?
 

Some videos you may like

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,958
If you want the result to be =IF($B389 > 0, $H389,""), use
Code:
Worksheets(2).Cells(Lastentry, "P") = "=IF($B" & Lastentry & " > " & 0 & ", $H" & Lastentry & ","""")"
 

Watch MrExcel Video

Forum statistics

Threads
1,127,430
Messages
5,624,744
Members
416,046
Latest member
Elliottj2121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top