'For Loop' For Selected Sheets/As Named In A Range

  • Thread starter Faraz A. Qureshi
  • Start date
F

Faraz A. Qureshi

Could one of you experts kindly provide a sample code so as to determine how
to carry out an exercise of "For Loop" in the following cases?

For Each "sheet in the selected sheets"
....
....
Next

and

For Each "sheet with name listed in a range (e.g. Sheet1!A1:A10)"
....
....
Next

Thanx in advance
 
M

Mike H

Hi,

Try these

Sub LoopSelected()
Dim sh As Worksheet
For Each sh In ThisWorkbook.Windows(1).SelectedSheets
MsgBox sh.Name ' do your stuff here
Next sh
End Sub


Sub LoopSelected2()
For Each c In Range("A1:A3")
MsgBox Sheets(c.Value).Name ' do your stuff here
Next
End Sub

Mike
 
J

Jacob Skaria

Hi Faraz

'Loop for selected sheets
For Each shtemp In ActiveWindow.SelectedSheets
MsgBox shtemp.Name
Next


'Loop with sheets mentioned in range
For Each shtemp In ActiveWorkbook.Sheets
If WorksheetFunction.CountIf(Range("A1:A10"), _
shtemp.Name) > 0 Then
MsgBox shtemp.Name
End If
Next

If this post helps click Yes
 
D

Don Guillett

Didn't notice. Just looked like homework...

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
Mike H said:
Don,

If it is the OP gets a lot of homework judging by the 800+ previous
posts!!!

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top