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

pingme89

Board Regular
Joined
Jan 23, 2014
Messages
170
Office Version
  1. 365
Platform
  1. Windows
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?
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
If you want the result to be =IF($B389 > 0, $H389,""), use
Code:
Worksheets(2).Cells(Lastentry, "P") = "=IF($B" & Lastentry & " > " & 0 & ", $H" & Lastentry & ","""")"
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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
Back
Top