Help on formula string

almecum

New Member
Joined
Jun 22, 2007
Messages
1
Hi
I have the following code which is to copy the formula that is used in the last row of a column and copy down to the blank cells. The First FormualInvStr works just fine but the second one FormualStatStr gives me an error on how the formula is entered. I cannot see why the second one is not accepted as correct. I have but the variable between " & I & " which is fine on the first but not the second.

The finished formula should look like this =IF(O2="","",IF(O2>0,"file in ZIP","")) the formula works fine.

Code:
Public Sub CopyFormulaToBlankCells()
 Dim i As Long
 Dim FormulaInvStr As String
 Dim FormulaStatStr As String
 
    i = Range("O65536").End(xlUp).Row + 1
 
    FormulaInvStr = "=VALUE(TRIM(CLEAN(A" & i & ")))"
    ActiveSheet.Range("O:O").SpecialCells(xlCellTypeBlanks).Formula = FormulaInvStr
 
    FormulaStatStr = "=IF(O" & i & " ="","",IF(O" & i & ">0,"file in ZIP",""))"
    ActiveSheet.Range("P:P").SpecialCells(xlCellTypeBlanks).Formula = FormulaStatStr

 End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
The finished formula should look like this =IF(O2="","",IF(O2>0,"file in ZIP","")) the formula works fine.

Code:
     FormulaStatStr = "=IF(O" & i & " ="","",IF(O" & i & ">0,"file in ZIP",""))"
You did not double up the quote marks that are internal to the Text string. Study my code below and compare it with yours...

FormulaStatStr = "=IF(O" & i & " ="""","""",IF(O2" & i & ">0,""file in ZIP"",""""))"
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,361
Members
449,080
Latest member
Armadillos

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