for each sheet in workbook

J

J.W. Aldridge

how to perform macro on each sheet in workbook.
(except first worksheet = "master data")

I've tried the subs below but only worked on one sheet.

Public Sub DoToAll()
Dim ws As Worksheet
For Each ws In Worksheets
Application.Run "filldown"
Next
End Sub

Sub loopthroughanddo()
x = Sheets("master data").Index
For Each sh In ThisWorkbook.Sheets
If sh.Index > x Then
Application.Run "filldown"
End If
Next
End Sub
 
B

Bernie Deitrick

A lot depends on what filldown does....it needs to know what the current ws
object is, so pass it to it. This example code copies cell A1 of every
sheet and fills it down column A to match column B.


Public Sub DoToAll()
Dim ws As Worksheet
For Each ws In Worksheets
If ws.Name <> "master data" filldown ws
Next ws
End Sub

Sub filldown(shtWS As Worksheet)
shtWS.Range("A1").Copy shtWS.Range("A2:A" & _
shtWS.Cells(Rows.Count, 2).End(xlUp).Row)
End Sub


HTH,
Bernie
MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top