private sub macros for hiding/unhiding columns

chobanne

Active Member
Joined
Jul 3, 2011
Messages
269
can someone plese help me to make this two codes

first is for active control X checkbox

i have checkbox in column A. When the box is checked i want columns B,C,D to be unhide and if box is uncheked i want columns B,C,D to be hiden.

second code is for active sheet. In case the column A is hidden for some reason also he previously mentioned checkbox must also be hidden.

Thank you
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try this code :

VBA Code:
Private Sub CheckBox1_Click()

    If Me.CheckBox1.Value = True Then
        Sheets(1).Columns("B:D").Hidden = True
    ElseIf Me.CheckBox1.Value = False Then
        Sheets(1).Columns("B:D").Hidden = False
    End If

End Sub

Selection_Change Event for your worksheet :

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Columns("A").Hidden = True Then
        ActiveSheet.CheckBox1.Visible = False
    Else
        ActiveSheet.CheckBox1.Visible = True
    End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,971
Messages
6,122,521
Members
449,088
Latest member
RandomExceller01

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