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
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
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.