Hide Columns VBA - refusing to hide random columns

hmltnangel

Active Member
Joined
Aug 25, 2010
Messages
290
Office Version
  1. 365
Platform
  1. Windows
Hi all.

Bit of an odd one. The code below should hide columns as requested. But when I run the Macro, Column AA wont hide. I even tried to be smart and record a basic macro to do that column specifically and then add Call MacroX in the code, but even then it wont hide the columns. BUT if I run MacroX separately on its own, it will hide it. In addition it randomly hides AE:AG as well. There is nothing in any other code in the workbook that refers to these columns. There are no merged cells in the columns that I can see. Whats causing the odd behaviour?

VBA Code:
Sub Reset()

ActiveSheet.Unprotect "S3"

    cells.Select
    Selection.EntireColumn.Hidden = False

    ActiveSheet.Range("C:C,P:P,R:R,T:T,X:X,AA:AA,AF:AF,AN:AN,AP:AP,AS:BB").EntireColumn.Hidden = True
   

ActiveSheet.Protect "S3"

End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Are you sure that you do not have any other VBA code interfering with this?
Is anything in column AA protected?
Any shapes or buttons in column AA?

Also, note that this:
VBA Code:
    cells.Select
    Selection.EntireColumn.Hidden = False
can be simplified to this:
VBA Code:
    cells.EntireColumn.Hidden = False

It typically is not necessary to select ranges in order to perform operations on them, and it actually makes you code faster to reduce/eliminate all the "Select" and "Activate" statements that you can.
 
Upvote 0
Oh dear. I truly should get the idiot of the day award. When I selected the macro to assign to the button.....

I have selected a different macro by accident. :oops::oops::oops:

Thanks for the tips on shortening things too - ive tidied that up.
 
Upvote 0

Forum statistics

Threads
1,215,148
Messages
6,123,309
Members
449,095
Latest member
Chestertim

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