Search code examples
excelexcel-2007hidevisiblevba

Excel VBA hide nth visible column


I have a worksheet for keeping track of time spent on different tasks - each workday is a column.

When each the week finishes, I would like to hide those columns (6, including totals) and keep working across.

Is there a way to take range from the 2nd to 6th visble column and hide it?

Ie, the first week I hide is columns B:G, then it's H:M, then N:S etc


Solution

  • This keeps column A showing and hides the next 6 visible columns:

    With ActiveSheet
        .Range(.Cells(1, 2), .Cells(1, .Columns.Count)).SpecialCells(xlCellTypeVisible).Range("A:F").EntireColumn.Hidden = True
    End With