How to write the code for toggle button...stupid things

Status
Not open for further replies.

nadirv8

New Member
Joined
Sep 12, 2006
Messages
9
Hi All,

Having issues with a macro im trying to get working for a button. All it is: selecting multiple columns and hiding them. This is it (below) and VB is rejecting the range,... or any range for that matter.

Code:
Private Sub CommandButton1_Click()
    Sheets("Holland").Select
    Range("D:D,H:H,L:L,P:P,T:T,X:X,AB:AB,AF:AF,AJ:AJ,AN:AN,AR:AR,AV:AV").Select
    Range("AV1").Activate
    Selection.EntireColumn.Hidden = True
    Sheets("CONTROL").Select
    Range("D1").Select
End Sub

Anyone got ideas of why its not working on the button?

Thankyou very very much!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

DominicB

Well-known Member
Joined
Oct 3, 2005
Messages
1,569
Good morning nadirv8

There is nothing wrong with the code per se. What sheet is the button placed on? You can have problems running code behind a button on Sheet A if it is selecting a range on Sheet B.

As a workaround you could put the code in a standard module and call it from your command button code.

HTH

DominicB
 
Status
Not open for further replies.

Forum statistics

Threads
1,141,626
Messages
5,707,491
Members
421,511
Latest member
mgroah1

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