Detecting multiple sheet selection

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,355
If the user selects more than one sheet, how can that be detected? And which sheets have they selected.

I've tried Selection (it is a Shape or a Range), ActiveSheet only returns one of the sheets.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Something along the lines of:

Code:
Sub SheetSelection()

    Dim Sht As Variant
    
    For Each Sht In ThisWorkbook.Windows("Book2.xlsx").SelectedSheets
        Debug.Print Sht.Name
    Next Sht

End Sub
 
Upvote 0
Possibly something like this.

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> CheckForGroupedSheets()<br>    <SPAN style="color:#00007F">Dim</SPAN> x <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> ws <SPAN style="color:#00007F">As</SPAN> Worksheet<br>    <SPAN style="color:#00007F">Dim</SPAN> wsList <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br><br>    x = ActiveWindow.SelectedSheets.Count<br>    <SPAN style="color:#00007F">If</SPAN> x > 1 <SPAN style="color:#00007F">Then</SPAN><br>        <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> ws <SPAN style="color:#00007F">In</SPAN> ActiveWindow.SelectedSheets<br>            wsList = wsList & vbLf & ws.Name<br>        <SPAN style="color:#00007F">Next</SPAN> ws<br>        MsgBox "Sheets selected:" & wsList<br>    <SPAN style="color:#00007F">Else</SPAN><br>        MsgBox "Only 1 sheet selected"<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,723
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top