ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA - identifying which worksheet is active (https://www.excelbanter.com/excel-programming/400574-vba-identifying-worksheet-active.html)

Boris

VBA - identifying which worksheet is active
 
Must be the weather or something but ...
I am having problems working out how to retrieve the sequential number of an
active worksheet (Activeworksheet does not supptort the various properties I
have tried...). Yeah, I know, should be trivial but I am obviosuly not
thinking of the right key words to find any help either. Suggestions much
appreciated. All I want to do really is count how many more worksheets IO
have after the active one.
Many thanks and best wishes.

Gary''s Student

VBA - identifying which worksheet is active
 
Sub which()
Dim n As String
n = ActiveSheet.Name
i = 1
For Each w In Worksheets
If w.Name = n Then
MsgBox (i)
End If
i = i + 1
Next
End Sub
--
Gary''s Student - gsnu200753

Boris

VBA - identifying which worksheet is active
 
Many thanks for the suggestion. This would definately work but is more
complicated than I had hoped for. I was hoping Index would work but I get an
error message when I try that - might of course be my typing.
Anyway, thanks for the suggestion.
Best wishes, Boris.

"Gary''s Student" wrote:

Sub which()
Dim n As String
n = ActiveSheet.Name
i = 1
For Each w In Worksheets
If w.Name = n Then
MsgBox (i)
End If
i = i + 1
Next
End Sub
--
Gary''s Student - gsnu200753



All times are GMT +1. The time now is 12:24 AM.

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