VBA: How to Unhide One or Multiple Columns

Yash Gaur Add Comment

This tutorial explains how to unhide one or multiple columns in Excel using VBA.

You can download the following dataset to practice.

Syntax to Unhide a Column

This code Columns("A").Hidden = False unhides the column A.

1. Unhide a Column

In this example we will try to unhide column B of a given data set.

Sub UnhideSingleColumn()
    Dim ws As Worksheet

    Set ws = ThisWorkbook.ActiveSheet
       ws.Columns("B").Hidden = False
End Sub
Press Run or F5 to run the above code.
VBA :  Unhide a Column
2. Unhide Multiple Columns

We want to unhide all the columns that are arranged continuously (one after another) from columns B through D.

Sub UnhideMultipleColumns()
    Dim ws As Worksheet
    
    Set ws = ThisWorkbook.ActiveSheet
       ws.Columns("B:D").Hidden = False
End Sub
Press Run or F5 to run the above code.
VBA : Unhide Multiple Columns
3. Unhide Specific Columns

Let's unhide columns B, D and F in a given data set. To do this we will use an array that stores the specific columns and then with the help of For Each loop we can apply ThisWorkbook.ActiveSheet.Columns(colNam).Hidden = False on each specific columns.

Sub UnhideSpecificColumns()
    Dim ws As Worksheet
    Dim colNam As Variant
    
    Set ws = ThisWorkbook.ActiveSheet
    For Each colNam In Array("B", "D", "F")
        ws.Columns(colNam).Hidden = False
    Next colNam
    
End Sub
Press Run or F5 to run the above code.
VBA : Unhide Specific Columns
Related Posts
Spread the Word!
Share
About Author:
Yash Gaur

Yash is pursuing an MBA in Finance with a keen interest in analytics. He enjoys working with data and leveraging his research and analytical skills to generate valuable insights.

Post Comment 0 Response to "VBA: How to Unhide One or Multiple Columns"
Next → ← Prev