calculation on every sheet through VBA

zeno

Board Regular
Joined
Feb 16, 2012
Messages
71
I try to make the same calculation on every specifically named sheet of a file. The structure of every sheet is the same, only the length of rows varies.
How can I write this in VBA?
Thank you.
 

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.
Without knowing which calculations, and where on each sheet, perhaps something like this might give you some ideas.

Code:
Sub zeno()
Dim lr As Long
Dim i As Long

For i = 1 To 20

    With Sheets("Sheet" & i)
    
        lr = Cells(Rows.Count, 1).End(xlUp).Row
    

        .Range("A2:A" & lr).Formula = "=YOUR FORMULA"
        .Range("A2:A" & lr).Value = .Range("A2:A" & lr).Value
        
    End With
    
Next i


End Sub
 
Upvote 0
Thank you for the code!
I have a quick follow-up:
I have particular names for the sheets, example "Data1", "Process1", etc.
How can I go through these sheets with those particular names?
 
Upvote 0
You're welcome. Maybe:

Code:
Sub zeno()
Dim y As Worksheet
Dim lr As Long

For Each y In Sheets(Array("Sheet1", "Sheet2", "Sheet4"))

    y.Activate
    
        lr = Cells(Rows.Count, 2).End(xlUp).Row  

        Range("A2:A" & lr).Formula = "YOUR FORMULA"
        Range("A2:A" & lr).Value = Range("A2:A" & lr).Value

Next y

End Sub

Change the names in the array to the sheets names you want too use.
 
Upvote 0

Forum statistics

Threads
1,215,013
Messages
6,122,690
Members
449,092
Latest member
snoom82

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