ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run the macro until activeSheet.previous.Select = Sheet2 (https://www.excelbanter.com/excel-programming/415806-run-macro-until-activesheet-previous-select-%3D-sheet2.html)

Heera

Run the macro until activeSheet.previous.Select = Sheet2
 
Hi,

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

Regards

Heera

joel

Run the macro until activeSheet.previous.Select = Sheet2
 
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

"Heera" wrote:

Hi,

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

Regards

Heera


Rick Rothstein \(MVP - VB\)[_2602_]

Run the macro until activeSheet.previous.Select = Sheet2
 
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


"Heera" wrote in message
...
Hi,

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

Regards

Heera



Heera

Run the macro until activeSheet.previous.Select = Sheet2
 
Thank you but I used this code.

Do While ActiveSheet.Name < "Sheet2"

My entire procedure

Loop


All times are GMT +1. The time now is 03:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com