ActiveX Control button to hide and unhide coloums

Browneh89

Board Regular
Joined
Mar 8, 2019
Messages
55
Office Version
  1. 365
Platform
  1. Windows
Hey,

I am a novice when it comes to using ActiveX Control and VBA to build macros but I am having incredible difficulty getting something simple to work. I want to build a macro which hides and unhides 3 columns in my excel sheet however when I run the macro it unhides unwanted columns and then hides the majority of the sheet..

I am at a bit of a loss as to why this is happening, could someone please enlighten me?

This is the VBA code which i'm running, i just used the record Macro feature and copied and pasted it into the "view code" option when you right click the activex control in design mode.

These Macros did work perfectly earlier on. i did add one massive merged row along the top of row one though.. is this the cause of the issue? if it is can i get around it without un merging that top row?



Sub showF()
'
' showF Macro
'


'
Columns("K:O").Select
Range("K2").Activate
Selection.EntireColumn.Hidden = False
Range("K2").Select
End Sub
Sub HideF()
'
' HideF Macro
'


'
Columns("L:N").Select
Range("L2").Activate
Selection.EntireColumn.Hidden = True
Range("K2").Select
End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Upvote 0
Definitely un merge the cells. You should avoid using merged cells at all cost because they create havoc for macros. Try the following:
Code:
Sub showF()
    Columns("K:O").EntireColumn.Hidden = False
    Range("K2").Select
End Sub

Sub HideF()
    Columns("L:N").EntireColumn.Hidden = True
    Range("K2").Select
End Sub
 
Upvote 0
Thank you for your responses! It was just the merged cells messing everything up. it kinda clicked the second i hit the send button.
 
Upvote 0

Forum statistics

Threads
1,214,645
Messages
6,120,711
Members
448,984
Latest member
foxpro

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