tigger6333
New Member
- Joined
- Sep 6, 2009
- Messages
- 43
Greetings.
I have a sheet with 7 buttons, each button attached to a macro that wil show/hide the relevant columns for the button.
The sheet has Row 1 with Headings but not in consecutive cells. Sometimes the cells are blank until the next heading appears.
So it may be A1=Heading1, B1-F1 Blank, G1=Heading2, H1-S1 Blank, T1-Heading3, etc.
Row 2 has subheadings for each section, no blank cells.
Each button relates to each Heading. So clicking the Button 1 will show/hide the columns from A to F, Button 2 G-S, and so on.
The macro I have attached to the buttons is as follows:
Sub ShowHide_Heading1()
If ActiveSheet.Columns("A:F").Hidden = True Then ActiveSheet.Columns("A:F").Hidden = False Else ActiveSheet.Columns("A:F").Hidden = True
End Sub
with each button having it's own macro with the column letters adjusted accordingly.
My question is this:
If I add a column in the sheet, the macros have to be manually adjusted.
How can I code in any changes so the code takes care of any column changes?
I was thinking of something like looking up the column of the desired heading (in the above example this would give the A parameter), and then looking up the column of the next heading - 1 ( this would give the F parameter). However my VBA skills are of the cut and paste variety, and I haven't worked out how to achieve my aim.
Is there anyone with the skill who can help?
Thanks in advance.
the Tigg
I have a sheet with 7 buttons, each button attached to a macro that wil show/hide the relevant columns for the button.
The sheet has Row 1 with Headings but not in consecutive cells. Sometimes the cells are blank until the next heading appears.
So it may be A1=Heading1, B1-F1 Blank, G1=Heading2, H1-S1 Blank, T1-Heading3, etc.
Row 2 has subheadings for each section, no blank cells.
Each button relates to each Heading. So clicking the Button 1 will show/hide the columns from A to F, Button 2 G-S, and so on.
The macro I have attached to the buttons is as follows:
Sub ShowHide_Heading1()
If ActiveSheet.Columns("A:F").Hidden = True Then ActiveSheet.Columns("A:F").Hidden = False Else ActiveSheet.Columns("A:F").Hidden = True
End Sub
with each button having it's own macro with the column letters adjusted accordingly.
My question is this:
If I add a column in the sheet, the macros have to be manually adjusted.
How can I code in any changes so the code takes care of any column changes?
I was thinking of something like looking up the column of the desired heading (in the above example this would give the A parameter), and then looking up the column of the next heading - 1 ( this would give the F parameter). However my VBA skills are of the cut and paste variety, and I haven't worked out how to achieve my aim.
Is there anyone with the skill who can help?
Thanks in advance.
the Tigg