Ungrouping sheets dependant on range

Pauljj

Well-known Member
Joined
Mar 28, 2004
Messages
2,046
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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
54,274
Office Version
  1. 365
Platform
  1. Windows
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?
 

Pauljj

Well-known Member
Joined
Mar 28, 2004
Messages
2,046
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
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
54,274
Office Version
  1. 365
Platform
  1. Windows
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>
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,711
Messages
5,833,251
Members
430,200
Latest member
ADLHMA2022

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
Top