i want to loop through some worksheets and the do a loop in each work sheet

liam1289

New Member
Joined
Apr 27, 2011
Messages
16
Worksheet code
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
MsgBox ws.Name
Next
End Sub

Then i have the looping code for working in each sheet but how to i add this to my code
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Code:
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
  With ws
     <ws-specific code>
  
  End With
End Sub
 
Upvote 0
that doesnt seem to work for me..i have 5 worksheets and i want to loop through each worksheet then move onto the next sheet, I have the code for looping in one sheet but it wont move on to the second sheet after
 
Upvote 0
Are you sure that the workbook you are running the code on is the same one hosting the code - as it stands the code runs on the active workbook

You could change
Code:
  For Each ws In ActiveWorkbook.Worksheets
to
Code:
  For Each ws In ThisWorkbook.Worksheets
to esnure it runs on the host workbook

The code below prints out the value of each cell to the immediate window from A1 to A10 (the inner loop) for each worksheet in the ActiveWorkbook (the outer loop)

Cheers

Dave

Code:
Sub test()
    Dim ws As Worksheet
    Dim rng1 As Range
    For Each ws In ActiveWorkbook.Worksheets
        MsgBox ws.Name
        For Each rng1 In ws.Range(ws.[a1], ws.[a10])
            Debug.Print rng1.Value
        Next
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,531
Messages
6,179,379
Members
452,907
Latest member
Roland Deschain

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