inputting formulas across multiple sheets with varying number of rows

mrider123

New Member
Joined
Nov 25, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Web
Hello everyone,

I am trying to input formulas into 80+ sheets with a varying number of rows. Below is the code I have that runs on the active sheet I am in(sheet7), and when running with stops, it shows that it goes to the next sheet(sheet8) but it's not actually writing the formulas in.

I also have the issue where, considering the number of rows vary, id like for the 'if formula' to go n29, n30, n31 and so on.

I am inputting the formula into column AG based on the number of rows with values in column N.



VBA Code:
Sub materialpricing()

Dim w As Long
Dim lrow As Long
Dim C As Range
Dim materialpricing As Variant

For w = 7 To ActiveWorkbook.Worksheets.Count
  With ActiveWorkbook.Worksheets(w)
    materialpricing= "=IF(N29=""delegated"",VLOOKUP(F29,'Deligated materials'!B:F,5,0),""Directed"")"
    lrow = Cells(Rows.Count, "N").End(xlUp).Row
            For Each C In Range("AG29:AG" & lrow)
                C.Formula = materialpricing
            Next
  End With
    
Next w
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Have not checked but could it be because deligated and delegated? Different spellings
 
Upvote 0

Forum statistics

Threads
1,223,996
Messages
6,175,864
Members
452,678
Latest member
will_simmo

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