我新手在編寫VBA代碼 - 我會geatfull如果你能指點我如何更有效地寫這個隱藏列代碼:這可以隱藏列代碼更有效地寫入?
代碼的目的是:如果在列的單元格F4是空然後隱藏列F等。
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("F4").Value = "" Then
Columns("F").EntireColumn.Hidden = True
Else
Columns("F").EntireColumn.Hidden = False
End If
If Range("G4").Value = "" Then
Columns("G").EntireColumn.Hidden = True
Else
Columns("G").EntireColumn.Hidden = False
End If
If Range("H4").Value = "" Then
Columns("H").EntireColumn.Hidden = True
Else
Columns("H").EntireColumn.Hidden = False
End If
If Range("I4").Value = "" Then
Columns("I").EntireColumn.Hidden = True
Else
Columns("I").EntireColumn.Hidden = False
End If
If Range("J4").Value = "" Then
Columns("J").EntireColumn.Hidden = True
Else
Columns("J").EntireColumn.Hidden = False
End If
If Range("K4").Value = "" Then
Columns("K").EntireColumn.Hidden = True
Else
Columns("K").EntireColumn.Hidden = False
End If
If Range("L4").Value = "" Then
Columns("L").EntireColumn.Hidden = True
Else
Columns("L").EntireColumn.Hidden = False
End If
If Range("M4").Value = "" Then
Columns("M").EntireColumn.Hidden = True
Else
Columns("M").EntireColumn.Hidden = False
End If
End Sub
我覺得奇怪,是隱藏列每當發生「變更」事件時。 – YowE3K