ActiveX Control button to hide and unhide coloums

Browneh89

New Member
Joined
Mar 8, 2019
Messages
7
Office Version
2013
Platform
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
 

Some videos you may like

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
40,719
Office Version
365
Platform
Windows

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,981
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
 

Browneh89

New Member
Joined
Mar 8, 2019
Messages
7
Office Version
2013
Platform
Windows
Thank you for your responses! It was just the merged cells messing everything up. it kinda clicked the second i hit the send button.
 

Watch MrExcel Video

Forum statistics

Threads
1,099,122
Messages
5,466,819
Members
406,500
Latest member
Tknotmaxx

This Week's Hot Topics

Top