Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For each loop in VBA for Excel

Status
Not open for further replies.

Mattyb33

MIS
Aug 24, 2010
10
GB
I am having a problem with a For Each loop in Excel VBA. I have a workbook with 4 sheets in it. I want to run a particular piece of code for each sheet in the workbook. I currently have the following code:-

Dim current as worksheet

For Each current in Worksheets

MY CODE HERE

Next

When I step through it the next statement doesn't select the next sheet. Can anyone help with this?!?
 


Please post VBA questions in forum707 for maximum results.

You need not SELECT anything...
Code:
Dim current as worksheet

For Each current in Worksheets
[b]
  With current
    'reference the worksheet here like
    msgbox .name  'to get the worksheet name in the mesage box
  end with
[/b]
Next

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top