Help with hiding Columns.

huzman

New Member
Joined
Oct 2, 2003
Messages
29
Hello!!

I am trying to accomplish the following: Cell A6 has a drop-down list. When A6 = "ABC", then column E, column F should be visible, else if A6 has anything else in it, column E, column F should be hidden.

The above should happen by itself, i.e. should not be triggered by anything, except the movement of the cursor from cell to cell.

Please help, keeping in mind that I am a beginner at VBA.

Thanks!!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
This could work for you:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng As Range
         '   only look at single cell changes
        If Target.Count > 1 Then Exit Sub
        Set rng = Range("A6")
        '   only look at that range
        If Intersect(Target, rng) Is Nothing Then Exit Sub
        If Range("A6").Value = "ABC" Then
            Range("E:F").EntireColumn.Hidden = False
            Else: Range("E:F").EntireColumn.Hidden = True
        End If
End Sub
Right click on the worksheet tab and select "View Code". Place this in there and then select from your list in A6. The code is triggered by making a selection from the list.

Hope that helps,

Smitty
 
Upvote 0

Forum statistics

Threads
1,214,790
Messages
6,121,608
Members
449,038
Latest member
apwr

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