inserting formula into worksheet range not working

ajm

Well-known Member
Joined
Feb 5, 2003
Messages
2,009
Office Version
  1. 365
Platform
  1. Windows
Hi, i have the following snippet which i am using to insert formulas into a worksheet. the first formula gets inserted where there are blank cells in the specified column, the second is supposed to overwrite whatever already exists in the specified column. the second one isn't working. Have i got the range specified correctly?

Code:
With Worksheets("Forward Plan")
   
    x = .Range("b36").End(xlDown).Row
    
   If x > 1 Then
   On Error Resume Next
        With .Range("Ag36:Ag" & x)

            .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=IF([@[Contract Value/Risk Matrix - Code]]="""",""10%""*1,VLOOKUP([@[Contract Value/Risk Matrix - Code]],ProjectVRM,3,0))"
            .NumberFormat = "0.00%"
        End With
        
        With .Range("Aj36:Aj" & x)

            .FormulaR1C1 = "=IFERROR(IF([@[Start Date for Next Activity]]="""","""",([@[Start Date for Next Activity]]+[@[Nbr Days for Next Activity]]*[@[Per Cent % Complete" & Chr(10) & "" & Chr(10) & "]]%)),[@[Start Date for Next Activity]])"
            .NumberFormat = "d/mm/yyyy"

        End With
    On Error GoTo 0
    End If
    
     
  End With
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Is this % sign in the image belwo in the right place ?
I can't test your code without an XL2BB of at least the headings of the table you are using, preferable with a line of sample data.
So if the above isn't the issue please post an XL2BB.
Also the Column AJ would need to be part of the same table.

1677051824015.png
 
Upvote 0
Is this % sign in the image belwo in the right place ?
I can't test your code without an XL2BB of at least the headings of the table you are using, preferable with a line of sample data.
So if the above isn't the issue please post an XL2BB.
Also the Column AJ would need to be part of the same table.

View attachment 85927
the formula was correct. i think the way i had the range stated was incorrect. in the first part, i use:

Code:
With .Range("Ag36:Ag" & x)

            .SpecialCells(xlCellTypeBlanks).FormulaR1C1 =

whereas, the second one i left out the .SpecialCells part. I got it to work by using .SpecialCells(xlCellTypeVisible)

Code:
 With .Range("Aj36:Aj" & x

            .SpecialCells(xlCellTypeVisible).FormulaR1C1 =
:
 
Upvote 0

Forum statistics

Threads
1,215,657
Messages
6,126,065
Members
449,286
Latest member
Lantern

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