ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Detecting Selected WorkSheet (https://www.excelbanter.com/excel-programming/278943-detecting-selected-worksheet.html)

LeoNgan

Detecting Selected WorkSheet
 
I would like to write a macro by depending on the user SELECTED
worksheet to work on something.

Is it possible to detect (know) which page or pages are selected by the
user? please

Thank a lot!!



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/


[email protected]

Detecting Selected WorkSheet
 
strWs = ActiveSheet.Name

Select Case strWs
Case "Red": ' Do this
Case "Blue": ' Do that
Case "Yellow":' Do the other.
Case Else: ' Do something else.
End Select

HTH
Paul
--------------------------------------------------------------------------------------------------------------
Be advised to back up your WorkBook before attempting to make changes.
--------------------------------------------------------------------------------------------------------------
I would like to write a macro by depending on the user SELECTED
worksheet to work on something.

Is it possible to detect (know) which page or pages are selected by the
user? please

Thank a lot!!



Serkan[_2_]

Detecting Selected WorkSheet
 
Private Sub Worksheet_Activate()
x = ActiveSheet.Name
i = 2
Do
If Sheets("Summary").Cells(i, 1) = "" Then
Sheets("Summary").Cells(i, 1) = Application.UserName
Sheets("Summary").Cells(i, 2) = x
Sheets("Summary").Cells(i, 3) = Now()
GoTo ext
Else
i = i + 1
End If
Loop
ext:
End Sub


you create a sheet, name= Summary
A column User name
B column sheet name which is using by user
C column Date


-----Original Message-----
I would like to write a macro by depending on the user

SELECTED
worksheet to work on something.

Is it possible to detect (know) which page or pages are

selected by the
user? please

Thank a lot!!



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from

http://www.ExcelForum.com/

.


Serkan[_2_]

Detecting Selected WorkSheet
 
write this code in all worksheet

-----Original Message-----
Private Sub Worksheet_Activate()
x = ActiveSheet.Name
i = 2
Do
If Sheets("Summary").Cells(i, 1) = "" Then
Sheets("Summary").Cells(i, 1) = Application.UserName
Sheets("Summary").Cells(i, 2) = x
Sheets("Summary").Cells(i, 3) = Now()
GoTo ext
Else
i = i + 1
End If
Loop
ext:
End Sub


you create a sheet, name= Summary
A column User name
B column sheet name which is using by user
C column Date


-----Original Message-----
I would like to write a macro by depending on the user

SELECTED
worksheet to work on something.

Is it possible to detect (know) which page or pages are

selected by the
user? please

Thank a lot!!



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from

http://www.ExcelForum.com/

.

.


LeoNgan[_2_]

Detecting Selected WorkSheet
 
No .. you mis-understand my meaning ..

in Excel you can select multiple worksheet by click the tab with shift
button (Sheet1, Sheet2, Sheet3, etc) and then apply function on them.

Now I would like to write a macro, which effect to the user's selected
worksheet. It is a dynamical situation.

Got it ??

:)



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/


Tom Ogilvy

Detecting Selected WorkSheet
 
VBA doesn't really support what you describe. Some of this functionality
can be achieved by using the selection object, but it is more robust to loop
through the sheets and make the change on each sheet

for each sh in ActiveWindow.Selectedsheets
' add code to do the work such as:
sh.Range("A1").Interior.ColorIndex = 3
Next

--
Regards,
Tom Ogilvy

"LeoNgan" wrote in message
...
No .. you mis-understand my meaning ..

in Excel you can select multiple worksheet by click the tab with shift
button (Sheet1, Sheet2, Sheet3, etc) and then apply function on them.

Now I would like to write a macro, which effect to the user's selected
worksheet. It is a dynamical situation.

Got it ??

:)



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/




LeoNgan[_3_]

Detecting Selected WorkSheet
 
No .. you mis-understand my meaning ..

in Excel you can select multiple worksheet by click the tab with shift
button (Sheet1, Sheet2, Sheet3, etc) and then apply function on them.

Now I would like to write a macro, which effect to the user's selected
worksheet. It is a dynamical situation.

Got it ??

:)



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/


Tom Ogilvy

Detecting Selected WorkSheet
 
No, you mis-understand. Excel VBA doesn't support this. I described a
workaround.

Got-it

--
Regards,
Tom Ogilvy

LeoNgan wrote in message
...
No .. you mis-understand my meaning ..

in Excel you can select multiple worksheet by click the tab with shift
button (Sheet1, Sheet2, Sheet3, etc) and then apply function on them.

Now I would like to write a macro, which effect to the user's selected
worksheet. It is a dynamical situation.

Got it ??

:)



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/




Tom Ogilvy

Detecting Selected WorkSheet
 
Anyway, all kidding aside, the problem you describe can be done using the
selection object as I originally stated:

Sub Tester2()
Dim shts As Sheets
Dim sh As Worksheet
Set shts = Worksheets(Array("Sheet1", "Sheet2", "Sheet3"))
Set sh = ActiveSheet
shts.Select
Range("A1").Select
Selection.Formula = "=Sum(C1:C30)"
sh.Select

End Sub

but also, in general, grouping sheets in vba (as above) is not supported.

--
Regards,
Tom Ogilvy

Tom Ogilvy wrote in message
...
No, you mis-understand. Excel VBA doesn't support this. I described a
workaround.

Got-it

--
Regards,
Tom Ogilvy

LeoNgan wrote in message
...
No .. you mis-understand my meaning ..

in Excel you can select multiple worksheet by click the tab with shift
button (Sheet1, Sheet2, Sheet3, etc) and then apply function on them.

Now I would like to write a macro, which effect to the user's selected
worksheet. It is a dynamical situation.

Got it ??

:)



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from

http://www.ExcelForum.com/







All times are GMT +1. The time now is 11:10 PM.

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