Ungrouping sheets dependant on range

Pauljj

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

Some videos you may like

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
47,926
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,013
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
47,926
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>
 

Watch MrExcel Video

Forum statistics

Threads
1,123,125
Messages
5,599,856
Members
414,342
Latest member
K Darrell Smith

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