VBA Code:
Private Sub CBExit_Click()
Dim col As Integer
For col = 2 To 72
If Worksheets("Results").Cells(3, col).Value = "" Then
Columns(col).Hidden = True
End If
Next
End Sub
Private Sub CBExit_Click()
Dim col As Long
For col = 72 To 2 Step -1
With Worksheets("Results").Cells(3, col)
.EntireColumn.Hidden = CBool(Len(.Value) = 0)
End With
Next
End Sub
Hi,
see if this update to your code does what you want
VBA Code:Private Sub CBExit_Click() Dim col As Long For col = 72 To 2 Step -1 With Worksheets("Results").Cells(3, col) .EntireColumn.Hidden = CBool(Len(.Value) = 0) End With Next End Sub
Dave
Thanks Dave. That worked. Never heard of CBool before. Guess that's what you get when you are self taught.VBA Code:
That description implies that as soon as you find the first blank cell (from B3 looking at your code) across then you hide that column and all the rest to column BU. If that is the case and those cells are truly blank (that is do not contain formulas returning "") then you could hide them all in one go without looping.I'm trying to find the first blank in row 3 and hide that column to column BU
Private Sub CBExit_Click()
With Sheets("Results")
On Error Resume Next
.Range(.Range("B3:BU3").SpecialCells(xlBlanks).Cells(1), .Range("BU3")).EntireColumn.Hidden = True
On Error GoTo 0
End With
End Sub