Macro to group rows after end of data, down to row 858

diygail123

New Member
Joined
Oct 24, 2018
Messages
25
Hi

Can anyone help with the following code, I am trying to get the macro to group the rows from the end of a list of data in column A (the end will be different each time the macro is ran), down to row 858, which will stay the same each time. What do I replace A135 with to make the macro dynamic please?

Thanks

Gail


Code:
Sub grouprows()'
' grouprows Macro
'
Dim activecell As Range
Set activecell = activecell


    Range("A7").Select
    Selection.End(xlDown).Select
    activecell.Offset(1, 0).Select
   
    Range("[COLOR=#ff0000]A135[/COLOR]:A858").Select
    Selection.Rows.Group
    
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Code:
Sub grouprows()
Cells.ClearOutline
Range([A7].End(xlDown)(2).Address & ":A858").Rows.Group
End Sub

Or :

Code:
Sub grouprows()
Cells.ClearOutline
Range([A7].End(xlDown)(2), [A858]).Rows.Group
End Sub
 
Last edited:
Upvote 0
Hi, both of these bug on the second line (Range etc) - runtime error 1004, Application defined or object defined error. What are the square brackets for?
Thanks

Gail
 
Upvote 0
Hi, both of these bug on the second line (Range etc) - runtime error 1004, Application defined or object defined error. What are the square brackets for?
Thanks

Gail

Do you have any data in column A below A7? If not, you will get Error 1004 (also in your original code).
If there is no data, and you want to group A8 to A858 then :
Code:
Sub grouprows()
Cells.ClearOutline
If [A8] = "" Then
    [A8:A858].Rows.Group
Else
    Range([A7].End(xlDown)(2), [A858]).Rows.Group
End If
End Sub

Re square brackets, [A7] is the same as Range("A7")
 
Upvote 0
Great thanks, that is doing the outline, but not actually closing the rows up, - how do I make it do that?

Gail
 
Upvote 0
Code:
Sub grouprows()
Cells.ClearOutline
If [A8] = "" Then
    [A8:A858].Rows.Group
Else
    Range([A7].End(xlDown)(2), [A858]).Rows.Group
End If
ActiveSheet.Outline.ShowLevels RowLevels:=1
End Sub
 
Upvote 0
Thanks that is now closing the rows up, however, the grouping dosent occur at all when I F5 the macro, but it does when I F8 throught it. Any ideas how to make F5 work?

Thanks

Gail
 
Upvote 0
Try FN+F5.
If doesn't work, maybe something to do with your settings. Try searching for "Excel VBE F5 not working".

The following should not make a difference but try :
Code:
Sub grouprows()
With ActiveSheet
    .Cells.ClearOutline
    If .[A8] = "" Then
        .[A8:A858].Rows.Group
    Else
        .Range(.[A7].End(xlDown)(2), .[A858]).Rows.Group
    End If
    .Outline.ShowLevels RowLevels:=1
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

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