VBA Module that Hides headers that are not needed (1 Viewer)

Bean Machine

Member
Local time
Today, 03:24
Joined
Feb 6, 2020
Messages
102
Hi All!

I will preface this by saying that I am fairly new to using VBA in excel. Essentially, my goal is to have a user input what "indicators" they would like to see data for, and then hide the other data that they do not specify they would like to see. I don't even know how I would go about this. I have provided two examples, one is the sheet that I want to use as the "driver" wherein the user specifies what they want to see, and the other is where the headers would be hidden or shown depending on what the user states they want to see. Any help would be greatly appreciated, and if you could explain how your code works (like a general overview) that would be immensely appreciated as I find that is the best way for me to learn.​

driver sheet example.png
indicator sheet example.png
 

MarkK

bit cruncher
Local time
Today, 00:24
Joined
Mar 17, 2004
Messages
8,181
I don't understand. I think you need to make a far more detailed description of the problem in order for someone to show you code.
 

June7

AWF VIP
Local time
Yesterday, 23:24
Joined
Mar 9, 2014
Messages
5,474
Based on simple workbook example provided, consider this code in a general module:
Code:
Sub HideColumn()
Dim strC As String, x As Integer
Worksheets("Sheet1").Range("A:G").EntireColumn.Hidden = True
For x = 2 To Worksheets("Sheet2").Range("A1").End(xlDown).Row
    Select Case Worksheets("Sheet2").Range("A" & x).Value
        Case "1a"
            strC = "A"
        Case "2b"
            strC = "C"
        Case "3c"
            strC = "E"
        Case "4d"
            strC = "G"
    End Select
    Worksheets("Sheet1").Range(strC & ":" & strC).EntireColumn.Hidden = False
Next
Worksheets("Sheet1").Range("A1").Select
End Sub
Then code behind a button on Sheet2 can call the above procedure.

Instead of requiring user to type header names on Sheet2, I would have them listed and user type Y or N in adjacent field and unhide where Y is entered or get fancy and use checkboxes.

Also, possibly want to close workbook without saving changes or make copy.
 
Last edited:

Bean Machine

Member
Local time
Today, 03:24
Joined
Feb 6, 2020
Messages
102
Based on simple workbook example provided, consider this code in a general module:
Code:
Sub HideColumn()
Dim strC As String, x As Integer
Worksheets("Sheet1").Range("A:G").EntireColumn.Hidden = True
For x = 2 To Worksheets("Sheet2").Range("A1").End(xlDown).Row
    Select Case Worksheets("Sheet2").Range("A" & x).Value
        Case "1a"
            strC = "A"
        Case "2b"
            strC = "C"
        Case "3c"
            strC = "E"
        Case "4d"
            strC = "G"
    End Select
    Worksheets("Sheet1").Range(strC & ":" & strC).EntireColumn.Hidden = False
Next
Worksheets("Sheet1").Range("A1").Select
End Sub
Then code behind a button on Sheet2 can call the above procedure.

Instead of requiring user to type header names on Sheet2, I would have them listed and user type Y or N in adjacent field and unhide where Y is entered or get fancy and use checkboxes.

Also, possibly want to close workbook without saving changes or make copy.
Hi!

First of all, I want to say thank you for the tips. So essentially, I want a user to specify which indicators they want measured by stating "Y" or "N" in column "B" on my "Driver" worksheet, then, I want any indicator columns that are not specified as "Y" to be hidden. So basically, I need code that checks what the user inputs on one worksheet, and then hides/unhides the columns as necessary on the "Ind" sheet. Hopefully this clears things up a bit. I have attached some more images. Any help would be fantastic. Thanks!

driver worksheet example.png
indicator worksheet example.png
 

June7

AWF VIP
Local time
Yesterday, 23:24
Joined
Mar 9, 2014
Messages
5,474
Code I provided should be adaptable to to your requirements. Have you tried?
 

Users who are viewing this thread

Top Bottom