Unhide Columns Containing Month and year

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,595
Office Version
  1. 2021
Platform
  1. Windows
I have several sheets containing the Month and Year in B4:M4 (Sheet3 to Sheets11)


I have set up months and year on sheet "Months" and linked this to Cell A2 using data validation


I have written code so that if for eg Oct 2018 is selected from the drop down list, that the column containing Oct 2018 on for eg sheet3 , then the col containing oct 2018 will be unhidden, but cannot get this to work i.e nothing happens


It would be appreciated if someone could assist me is resolving this





Code:
 Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim col As Long
Dim c As Range

Application.ScreenUpdating = False

    If Target.Address(0, 0) <> "A2" Then Exit Sub
    Columns("B:M").Hidden = False
    Set c = Range("B4:M4").Find(Target, LookIn:=xlValues, LookAt:=xlPart)
    Columns("B:M").Hidden = True

    If Not c Is Nothing Then
    c.EntireColumn.Hidden = False
    Else
    MsgBox Target & " not found", 48, "ERROR"
    End If

Application.ScreenUpdating = True

End Sub
 
Last edited:

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi there. I have tried your code in a simple sheet just looking for the content of A2 as text, and it works fine. I presume that this code is in the worksheet code area of each Sheet3 to Sheet11. If that is the case, then I suspect that not all your cells are the same format and so the find isn't working. Just to check this out, temporarily change the format of A2 and B4 to M4 to a number, and see what they are actually set to.
 
Upvote 0
Thanks for your input. Will check & amend where necessary
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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