AP1
AP1

Reputation: 167

VBA - How to unhide columns?

UPDATE: So I found the issue. The macro runs when the user selects a link on the worksheet. I had the link set up to the unhide rows macro.

I'm having an issue unhiding columns using VBA. I've been using this link as a basis to try solving my issue, but it isn't working for me.

Macro to Hide/Unhide Columns in Excel

This is my code right now:

Public Sub a_view_calc_columns()
     Dim calc as Worksheet
     Dim rng as Range

     Set calc = ThisWorkbook.Sheets("Calc")
     Set rng = calc.Range("A:T")

     rng.EntireColumn.Hidden = False

I've also tried:

rng.Column.EntireColumn.Hidden = False

And

With Columns("A:T")
     If .EntireColumn.Hidden = True Then
          .EntireColumn.Hidden = False
     End If
End With

I'm using Excel 2016.

I should note that there will be data in columns A:T and that I'm manually hiding columns G & H to test the code.

Upvotes: 0

Views: 11210

Answers (1)

QHarr
QHarr

Reputation: 84475

Here is a simple example

Option Explicit

Sub test()
    With ActiveSheet
        If .Columns("G:H").EntireColumn.Hidden Then
            MsgBox "Hidden"
            .Columns("G:H").EntireColumn.Hidden = False
        Else
           MsgBox "Those columns aren't hidden"
        End If
    End With
End Sub

Upvotes: 3

Related Questions