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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,468
Office Version
  1. 365
Platform
  1. Windows

mumps

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

Board Regular
Joined
Mar 8, 2019
Messages
55
Office Version
  1. 365
Platform
  1. 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,129,382
Messages
5,635,931
Members
416,888
Latest member
Mike66

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
Top