Hide columns with VBA code

Aldwin

New Member
Joined
Jun 16, 2013
Messages
8
Hi all,

I want to have a VBA Code how automaticaly hide columns.
There are two excelsheets: "Inleiding" and "Checklist Toelichting Algemeen".
There are three criteria in c8 of excelsheet "Inleiding": "Groot", "Middelgroot" and "Klein".
The VBA code need to do the following things:
- If cel c8 in excelsheet "Inleiding" give "Groot" then hide column D and E in excelsheet "Checklist Toelichting Algemeen".
- If cel c8 in excelsheet "Inleiding" give "Middelgroot" then hide column C and E in excelsheet "Checklist Toelichting Algemeen".
- If cel c8 in excelsheet "Inleiding" give "Klein" then hide column C and D in excelsheet "Checklist Toelichting Algemeen".
Thanks in advance.

Regards,

Aldwin
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Possibly put the code below in the "Inleiding" sheets code module (right click the "Inleiding" sheet tab, click View Code, paste the code below in the window that appears.

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Address = "$C$8" Then
         
         Sheets("Checklist Toelichting Algemeen").Columns("A:F").EntireColumn.Hidden = False

            Select Case Target.Text

            Case "Groot"
                Sheets("Checklist Toelichting Algemeen").Columns("D:E").EntireColumn.Hidden = True

            Case "Middelgroot"
                Sheets("Checklist Toelichting Algemeen").Columns("C:C").EntireColumn.Hidden = True
                Sheets("Checklist Toelichting Algemeen").Columns("E:E").EntireColumn.Hidden = True

            Case "Klein"
                Sheets("Checklist Toelichting Algemeen").Columns("C:D").EntireColumn.Hidden = True

            End Select
        End If
End Sub
 
Upvote 0
reducable to:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$C$8" Then
       with Sheets("Checklist Toelichting Algemeen")
         .Columns("A:F").Hidden = False
         .Columns("D:E").Hidden = Target="Groot"
         .Range("C1,E1").EntireColumn.Hidden = Target="Middelgroot"
         .Columns("C:D").Hidden = Target="Klein"
       End With
    End if
End Sub
 
Last edited:
Upvote 0
Interesting, haven't tried just putting the action = target = value before.
Will try it this evening.
Thanks for that snb.
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,243
Members
449,075
Latest member
staticfluids

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