简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM