Show / Hide macro issue

Fishboy

Well-known Member
Joined
Feb 13, 2015
Messages
4,267
Hi all,

I have successfully added in a number of show / hide macros attached to buttons in order to manage the visibility of various rows / columns in an Excel 2010 spreadsheet.

Over time, as more data has been provided it has become necessary to insert additional columns or rows into the spreadsheet, but doing so obviously throws all of the show / hide macros out of whack.

Am I missing a trick here? Is it possible to use relative column or row labels which will dynamically update when new columns or rows are added, or do I have to manually go back through all of the macros and update them with the new values?

Here is an example of what I have been using so far:

Sub Branch 2()
Columns("C:C").Hidden = Not Columns("C:C").Hidden
Columns("E:AB").Hidden = Not Columns("E:AB").Hidden
End Sub

The above will hide / show all columns from C to AB, leaving only D showing. I have a similar macro tailored for each column for all the other office locations, which are listed alphabetically across Row 2, starting in column C.

Now I need to add in new office locations, which will also need to fit in alphabetically to the current list of branches. This means inserting new columns at the relevant alphabetic location, but doing so means the macros for all columns to the right of the new one no longer tie in with the correct column references in the existing macros.

This is driving me mad and I am one step away from just manually updating all the macros, but I know this is likely to come up again in the same spreadsheet in the future and I will have to go through it all over again.

Is there a way to keep the macro relative to its location, which updates dynamically if the column moves?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi Fishboy,

I will stand corrected but I believe the macro code will have to be updated manually.

Cheers, InaCell.
 
Upvote 0
Thanks InaCell, I feared as much. I'm going to hold out a little longer and see if anyone else has any suggestions, but it does look like it's going to be a heavily manual process :(
 
Upvote 0
You can still use replace in Visual Basic and select Current Project to use all Modules. Might make it a bit faster. :)

Cheers, InaCell.
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,318
Members
449,218
Latest member
Excel Master

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