Run the macro until activeSheet.previous.Select = Sheet2

  • Thread starter Thread starter Heera
  • Start date Start date
H

Heera

Hi,

I want a loop which will stop if the activesheet is "Sheet2" of the
workbook.

Regards

Heera
 
Found = False
for sht in sheets
if sht.name = "Sheet2" then
Found = true
exit for
end if
next sht
if Found = true then
'enter your code here
end if
 
Try a construction like this...

Dim WS As Worksheet
.....
.....
For Each WS In Worksheets
If WS.Name = "Sheet2" Then
'
' You found Sheet2, so execute your code here
'
Exit For
End If
Next
......
......

Note the Exit For statement after your Sheet2 code... that stops the loop
from continuing on (you already found Sheet2, so there is no longer any need
to keep looping looking for it).

Rick
 

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

Back
Top