MS Excel VBA Code Will Not Expand when Rows are Grouped

OilEconomist

Active Member
Joined
Dec 26, 2016
Messages
439
Office Version
  1. 2019
Platform
  1. Windows
Thanks in advance for your assistance. When I run the code and the groups below those words are collapsed, why won't it expand it.

Please note that this code has been taken from a larger Macro and reduced and tested. I understand the code can be simplified for what I am doing, but I have it that way so I can relate it to the larger code it was extracted. I would like to keep that the same and just have the issue corrected.

Book4
ABCDEFG
1
2
3
4HEADING
5Section 1
6
7
8Section 2
9
10
11
12Section 3
13
14
15
16
17
18
19
Sheet1


VBA Code:
Sub Expand_Issue()



'Dimensioning
    
    Dim CF As Long, CL As Long, RH As Long, RF As Long, RL As Long
    Dim ShtNmActv As String, MacroText As String
    
    Dim aCell As Range, Rng As Range
    
    

'Code
    
    ShtNmActv = "Sheet1"
    
    
    
    
    
    With Sheets(ShtNmActv)
        
        On Error Resume Next
        CF = .Cells.Find("*", SearchOrder:=xlByColumns, LookIn:=xlValues, searchdirection:=xlNext).Column
        
        On Error Resume Next
        CL = .Cells.Find("*", SearchOrder:=xlByColumns, LookIn:=xlValues, searchdirection:=xlPrevious).Column
        
        On Error Resume Next
        RF = .Cells.Find("*", SearchOrder:=xlByRows, LookIn:=xlValues, searchdirection:=xlNext).Row
        RH = RF
        RF = RH + 1
        
        On Error Resume Next
        RL = .Cells.Find("*", SearchOrder:=xlByRows, LookIn:=xlValues, searchdirection:=xlPrevious).Row
        
        
        
        'Set Range
         Set Rng = .Range(.Cells(RF, CF), .Cells(RL, CF))
        
        
        'Loop for first section
         For Each aCell In Rng
            If aCell = "Section 1" Then
                If .Rows(aCell.Row + 1).Hidden = True Then
                    .Rows(aCell.Row + 1).Expand
                End If
                Exit For
            End If
         Next aCell
        
        
        'Loop for second section
         For Each aCell In Rng
            If aCell = "Section 3" Then
                If .Rows(aCell.Row + 1).Hidden = True Then
                    .Rows(aCell.Row + 1).Expand
                End If
                Exit For
            End If
         Next aCell

        
    End With
    


End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

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