Grouping VBA

Mr_Ragweed

Board Regular
Joined
Dec 10, 2012
Messages
74
Potentially silly question here - my apologies in advance....
I would like to basically recreate the grouping userform from the ribbon in Excel 2010. I have written a series of macros and userforms in a program that creates a lot of PT's and then lets the user group the data. A userform gives the user the choice to group by "gross margin dollars" or "gross margin %" and then click select. Upon that click event the data selected is "auto grouped" but filled with many decimals. The users of this program are not necessarily excels users and i cannot count count on them to find the "group" option on the data page and adjust the grouping range to their needs (This is a necessary step in the analysis). The pop-up provided in excel from the ribbon is sufficent (other than i might change some of the nomenclature to make the logic more intuitive for nonusers).
I see my options as this:
#1 recreate the grouping from the ribbon and have it launch on the click action in my userform
or #2 maybe i can make a "hot button" in a cell that automatically calls the one that exists in excel.

Any help is greatly appreciated. Thanks much to those who have at least taken the time to read through my babbling.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I get where you're going. I'm still digesting it. Most of what i saw on the link you provided is over my head. I'm pretty tall therefore i can see it - just not sure if i can reach it :laugh:.
This program will be available to 40+ users of varying skill levels so i'm trying to keep it simple. I know in the context of this forum that recreating a feature that already exists in excel is just plain goofy, but boy do i think that is my best route. I want the "Group" button on the data tab ribbon (or a reasonable facsimile thereof) to actually appear on the worksheet(s).
Maybe thats what the video in the link was showing me. Maybe i'm not as tall as I think :laugh:
Thank you for the help you've provided so far. It did jog my memory on a few things i've read. This forum and the book "VBA abd macros excel 2010" have been my guidance throughout the project.
 
Upvote 0
Update - So i've created/recreated a "group" userform like the one used to group data from pivot tables. I recorded a macro for using the "group" feature already supplied with excel. I'm thinking though that since that is a hard coded version, somewhere i've gone astray. I get a "Group method of range calss failed" error. (not my first 'method of range' issue in my VBA journey hahahaha).
My code is below: (line causing the error is in red)

Rich (BB code):
Private Sub CmdRegroup_Click()
Dim FinalRow As Long
FinalRow = ActiveSheet.Cells(Application.Rows.Count, 1).End(xlUp).Row
If TextBox3.Value = True Then
    If TextBox2.Value = True Then
        If TextBox1.Value = True Then
        
            If Range("I13").Value = "List" Then
    Range("F4:F" & FinalRow).Select
    Selection.Group Start:=TextBox3.Value, End:=TextBox2.Value, By:=TextBox1.Value
            ElseIf Range("N13").Value = "List" Then
            Range("K4:K" & FinalRow).Select
            Selection.Group Start:=TextBox3.Value, End:=TextBox2.Value, By:=TextBox1.Value
                ElseIf Range("J13").Value = "List" Then
                Range("G4:G" & FinalRow).Select
                Selection.Group Start:=TextBox3.Value, End:=TextBox2.Value, By:=TextBox1.Value
                    ElseIf Range("O13").Value = "List" Then
                    Range("L4:L" & FinalRow).Select
                    Selection.Group Start:=TextBox3.Value, End:=TextBox2.Value, By:=TextBox1.Value
            End If
        End If
    End If
End If
Unload Me

End Sub

Basically i'm wanting the values in the userform to be the range and increment it sorts the data by.
Any help would be greatly appreciated. (Also, if anyone could remind me on how to put code breaks in, that would be awesome 'cause i'm pretty sure i just did it wrong again)
 
Last edited by a moderator:
Upvote 0
Ha. I found the code tags.

Rich (BB code):
Private Sub CmdRegroup_Click()
Dim FinalRow As Long
FinalRow = ActiveSheet.Cells(Application.Rows.Count, 1).End(xlUp).Row
If TextBox3.Value = True Then
    If TextBox2.Value = True Then
        If TextBox1.Value = True Then

            If Range("I13").Value = "List" Then
    Range("F4:F" & FinalRow).Select
Selection.Group Start:=TextBox3.Value, End:=TextBox2.Value, By:=TextBox1.Value
            ElseIf Range("N13").Value = "List" Then
            Range("K4:K" & FinalRow).Select
            Selection.Group Start:=TextBox3.Value, End:=TextBox2.Value, By:=TextBox1.Value
                ElseIf Range("J13").Value = "List" Then
                Range("G4:G" & FinalRow).Select
                Selection.Group Start:=TextBox3.Value, End:=TextBox2.Value, By:=TextBox1.Value
                    ElseIf Range("O13").Value = "List" Then
                    Range("L4:L" & FinalRow).Select
                    Selection.Group Start:=TextBox3.Value, End:=TextBox2.Value, By:=TextBox1.Value
            End If
        End If
    End If
End If
Unload Me

End Sub
 
Last edited by a moderator:
Upvote 0
Thanks Smitty!!
And by the way to anyone who has been reading....i think i solved my issue!!!! Basically i didn't need to use the textbox values from the user. When you select a cell in a pivot table i guess it automatically gets the beginning and end range of the data. I left the "By:=....." as a textbox input from the user and voila! I would like to clean up the extensive decimals for visual purposes but now i'm getting frivolous.
Here's is the code:
Code:
Private Sub CmdRegroup_Click()
Dim FinalRow As Long
FinalRow = ActiveSheet.Cells(Application.Rows.Count, 1).End(xlUp).Row
'If TextBox3.Value = True Then
    'If TextBox2.Value = True Then
        If TextBox1.Value = True Then
        
            If Range("I13").Value = "List" Then
    Cells(4, 6).Select
    Selection.Group Start:=True, End:=True, By:=TextBox1.Value
            ElseIf Range("N13").Value = "List" Then
            Cells(4, 7).Select
            Selection.Group Start:=True, End:=True, By:=TextBox1.Value
                ElseIf Range("J13").Value = "List" Then
                Cells(4, 11).Select
                Selection.Group Start:=True, End:=True, By:=TextBox1.Value
                    ElseIf Range("O13").Value = "List" Then
                    Cells(4, 12).Select
                    Selection.Group Start:=True, End:=True, By:=TextBox1.Value
            End If
        'End If
    'End If
End If
Unload Me

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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