Macro to expand groups (columns)?

lulu840

New Member
Joined
May 9, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I'm self-taught in excel and so still have much to learn and have never used macros before. I want to add a button that expands columns B through E (The button will be in column A). Can someone please help me with how to do this?
 

Attachments

  • excel question.PNG
    excel question.PNG
    9.8 KB · Views: 10

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I'm self-taught in excel and so still have much to learn and have never used macros before.
The best way to start in my opinion is to record some simple macros and review the code it creates.
From there, check out the free course on Excel VBA here. The Beginner course in the Playlist will give you a very solid starting point.

However, the Excel Workbook must be saved as a Macro-enabled Workbook if not one already. From there you can use the following VBA code I got by recording a macro where I unhid Columns B:E:

VBA Code:
Sub UnhideB2E()
    Columns("A:F").Select
    Selection.EntireColumn.Hidden = False
    Range("A1").Select 'This line just selects cell A1 in order to deselect the Columns
End Sub

As for creating buttons and assigning macros to them...YouTube is really your best option as there are many possibilities.
That course I linked above covers everything you need to both record a macro, create buttons/shapes/objects and assign macros to them.

Best of luck...
 
Upvote 0
The best way to start in my opinion is to record some simple macros and review the code it creates.
From there, check out the free course on Excel VBA here. The Beginner course in the Playlist will give you a very solid starting point.

However, the Excel Workbook must be saved as a Macro-enabled Workbook if not one already. From there you can use the following VBA code I got by recording a macro where I unhid Columns B:E:

VBA Code:
Sub UnhideB2E()
    Columns("A:F").Select
    Selection.EntireColumn.Hidden = False
    Range("A1").Select 'This line just selects cell A1 in order to deselect the Columns
End Sub

Unhiding has nothing to do with expanding a column that has a data grouping.
 
Upvote 0
I'm self-taught in excel and so still have much to learn and have never used macros before. I want to add a button that expands columns B through E (The button will be in column A). Can someone please help me with how to do this?

Try this:
VBA Code:
Sub Expand_Grouping()
    ActiveSheet.Columns(2).ShowDetail = True
End Sub

Also, how to assign a macro to a button.

 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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