Loop through all sheets in an open excel workbook using VBA

The code below does the following:

  1. Loops through all sheets in the active excel workbooks
  2. activates each of the sheets
  3. calls myFunction subroutine (which would normally be a set of actions done in the active sheet)
Sub myMainProgram ()
   For i = 1 To Sheets.count
      Sheets(i).Activate
      Call myFunction()
   Next i
End Sub

Sub myFunction ()
   'Do something in my activesheet
End Sub
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s