mattcottrell
Technical User
I am trying to hide certain columns based on a value entered into a cell.
This is what I currently have:
Sub Prepare()
Dim MonthNumber As Integer
Dim MonthRange As Range
MonthNumber = ActiveSheet.Range("C3".Value
If MonthNumber = 1 Then
Set MonthRange = Columns("P:AA"
ElseIf MonthNumber = 2 Then
Set MonthRange = Columns("Q:AB"
End If
Sheets(Array("100%", "Absence", "Absence Per Head", "Pension Take Up", _
"Labour Turnover", "Staff Turnover", "Headcount", "Starters", "Leavers", "Summary") _
.Select
Sheets("100%".Activate
Columns("C:AL".EntireColumn.Hidden = True
MonthRange.EntireColumn.ColumnWidth = 8.43
End Sub
All the sheets are in exactly the same format.
The code:
"Columns("C:AL".EntireColumn.Hidden = True" works fine, but
"MonthRange.EntireColumn.ColumnWidth = 8.43" does not work.
Does anybody know how to successfully pass a column variable to VBA.
Many thanks in advance
Matt
This is what I currently have:
Sub Prepare()
Dim MonthNumber As Integer
Dim MonthRange As Range
MonthNumber = ActiveSheet.Range("C3".Value
If MonthNumber = 1 Then
Set MonthRange = Columns("P:AA"
ElseIf MonthNumber = 2 Then
Set MonthRange = Columns("Q:AB"
End If
Sheets(Array("100%", "Absence", "Absence Per Head", "Pension Take Up", _
"Labour Turnover", "Staff Turnover", "Headcount", "Starters", "Leavers", "Summary") _
.Select
Sheets("100%".Activate
Columns("C:AL".EntireColumn.Hidden = True
MonthRange.EntireColumn.ColumnWidth = 8.43
End Sub
All the sheets are in exactly the same format.
The code:
"Columns("C:AL".EntireColumn.Hidden = True" works fine, but
"MonthRange.EntireColumn.ColumnWidth = 8.43" does not work.
Does anybody know how to successfully pass a column variable to VBA.
Many thanks in advance
Matt