VBA Loop through selected range of sheets

acharsanthosh

New Member
Joined
Dec 20, 2017
Messages
9
Hello Folks,

I have a workbook with 45 sheets and all the sheet names listed in 45th Tab naming "Other Data".

Now I want to run a for each loop based on the sheet list name range in "Other Data Tab".

Can anyone please help me out with this?

Am able to run the loop for all the worksheets as below

Sub loopforeach

Dim ws as Worksheet

For Each ws in Worksheets

Next

End Sub

Looking forward for your help!!

Thank you

San
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Assuming the sheet names are in column "A" of sheet "Other Data" , try this.
Code:
[COLOR="Navy"]Sub[/COLOR] MG20Dec54
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, R [COLOR="Navy"]As[/COLOR] Range, ShtRng [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]With[/COLOR] Sheets("Other Data")
[COLOR="Navy"]Set[/COLOR] Rng = .Range("A1", .Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]With[/COLOR] Sheets(Dn.Value)
      [COLOR="Navy"]Set[/COLOR] ShtRng = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
            [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] R [COLOR="Navy"]In[/COLOR] ShtRng
               MsgBox R.Address(external:=True)
               '[COLOR="Green"][B] Do something Here with column "A" range for Individual sheets[/B][/COLOR]
   
            [COLOR="Navy"]Next[/COLOR] R
   [COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Looks like he just forgot one closing "End With" statement.
It should be between the "Next Dn" and "End Sub" rows.
 
Upvote 0
Sorry, the "End With" was originally at the end of the sub, and I forgot to copy it.
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG20Dec07
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, R [COLOR="Navy"]As[/COLOR] Range, ShtRng [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]With[/COLOR] Sheets("Other Data")
    [COLOR="Navy"]Set[/COLOR] Rng = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]With[/COLOR] Sheets(Dn.Value)
      [COLOR="Navy"]Set[/COLOR] ShtRng = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
            [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] R [COLOR="Navy"]In[/COLOR] ShtRng
               MsgBox R.Address(external:=True)
               '[COLOR="Green"][B] Do something Here with column "A" range for Individual sheets[/B][/COLOR]
   
            [COLOR="Navy"]Next[/COLOR] R
   [COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,252
Members
449,075
Latest member
staticfluids

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