Red over White
Board Regular
- Joined
- Jul 16, 2011
- Messages
- 123
- Office Version
- 365
- Platform
- MacOS
I'm hoping someone will be able to help me with the following code
Sub HideCols()
Sheets("Sheet1").Activate
Dim Int1 As Integer
With Sheets("Sheet1")
.Columns("L:CR").EntireColumn.Hidden = False
For Int1 = 12 To 96
.Columns(Int1).Hidden = Cells(3, Int1).Value <> 0
Next Int1
End With
Range(Cells(2, 47), Cells(2, 96)).SpecialCells(xlCellTypeBlanks)(1).Select
' Hide columns that aren't required
Dim rng As Range
Dim Col1 As Integer
Col1 = ActiveSheet.Columns(ActiveCell.Column).Rows(1)
' set rng to refer to required range
Set rng = Range(3 & ":" & Col1 - 1)
rng.Select
Selection.EntireColumn.Hidden = True
End Sub
I'm assuming the issue is surrounding Col1, in that it will be in the "A1" format, and should be a number. However, I don't know how to define Col1 as the identified column as a number.
Thanks
Sub HideCols()
Sheets("Sheet1").Activate
Dim Int1 As Integer
With Sheets("Sheet1")
.Columns("L:CR").EntireColumn.Hidden = False
For Int1 = 12 To 96
.Columns(Int1).Hidden = Cells(3, Int1).Value <> 0
Next Int1
End With
Range(Cells(2, 47), Cells(2, 96)).SpecialCells(xlCellTypeBlanks)(1).Select
' Hide columns that aren't required
Dim rng As Range
Dim Col1 As Integer
Col1 = ActiveSheet.Columns(ActiveCell.Column).Rows(1)
' set rng to refer to required range
Set rng = Range(3 & ":" & Col1 - 1)
rng.Select
Selection.EntireColumn.Hidden = True
End Sub
I'm assuming the issue is surrounding Col1, in that it will be in the "A1" format, and should be a number. However, I don't know how to define Col1 as the identified column as a number.
Thanks