Run the macro until activeSheet.previous.Select = Sheet2

H

Heera

Hi,

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

Regards

Heera
 
J

Joel

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
 
R

Rick Rothstein \(MVP - VB\)

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
 
H

Heera

Thank you but I used this code.

Do While ActiveSheet.Name <> "Sheet2"

My entire procedure

Loop
 

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