Hi everyone,
I'm trying to hide columns depending on whether one of the cells is blank or not, and I need to apply this to several sheets, all of which have the same layout and formatting.
I'm very much a beginner with VBA, so if anyone can suggest a better way of going about it I would really appreciate it.
Code
Private Sub CommandButton1_Click()
If Range("B44").Value = "" Then
Columns(5).Hidden = True
Columns(6).Hidden = True
Else
Columns(5).Hidden = False
Columns(6).Hidden = False
End If
If Range("B46").Value = "" Then
Columns(7).Hidden = True
Columns(8).Hidden = True
Else
Columns(7).Hidden = False
Columns(8).Hidden = False
End If
If Range("B48").Value = "" Then
Columns(9).Hidden = True
Columns(10).Hidden = True
Else
Columns(9).Hidden = False
Columns(10).Hidden = False
End If
If Range("B50").Value = "" Then
Columns(11).Hidden = True
Columns(12).Hidden = True
Else
Columns(11).Hidden = False
Columns(12).Hidden = False
End If
'copies the column widths and their formats
Sheets("Sheet7").Range("E:BT").Copy
Sheets("Sheet9").Range("A:C").Paste = xlColumnWidths
End Sub
Display More
Thankyou all,
Matt