Ungrouping sheets dependant on range

Pauljj

Well-known Member
Joined
Mar 28, 2004
Messages
2,047
I have a code below which groups all the sheets in the workbook together once a cell is activated. How can i have it that if cells in rows 1 to 15 are selected they become ungrouped?

Private Sub workbook_activate()

Sheets.Select

End Sub

Many thanks

Paul
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I have a code below which groups all the sheets in the workbook together once a cell is activated.
Do you mean when any cell in the Workbook is activated?

How can i have it that if cells in rows 1 to 15 are selected they become ungrouped?
Do we have to check for cells selected in rows 1:15 in all the sheets, or a particular sheet, or the active sheet?
 
Upvote 0
Yes this is for when the workbook is activated.

If someone selects a cell in rows 1 to 15 in sheet 1, then I would need the sheets to be ungrouped, if someone selects a cell on any other row in sheet 1, then the sheets should group

Many thanks
Paul
 
Upvote 0
Try this:

Right click "Sheet 1", choose "View Code" and paste the following code.

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_SelectionChange(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)
    <SPAN style="color:#00007F">If</SPAN> Target.Count > 1 <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
    <SPAN style="color:#00007F">If</SPAN> Target.Row > 15 <SPAN style="color:#00007F">Then</SPAN>
        Sheets.Select
    <SPAN style="color:#00007F">Else</SPAN>
        Me.Select
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0

Forum statistics

Threads
1,214,789
Messages
6,121,605
Members
449,038
Latest member
Arbind kumar

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