我在excel中的VBA是全新的,但我一直试图隐藏并显示依赖于特定单元格中的值的行。
到目前为止,我可以让这段代码正常工作;
Private Sub Worksheet_Change(ByVal Target As Range)
Dim LastRow As Long, c As Range
Application.EnableEvents = False
LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
On Error Resume Next
For Each c In Range("A10:A15", "A17:A22")
If c.Value = "" Then
c.EntireRow.Hidden = True
ElseIf c.Value > 0 Then
c.Activate
c.EntireRow.Hidden = False
End If
Next
On Error GoTo 0
Application.EnableEvents = True
End Sub
但是当我尝试添加更多单元格时,例如" A24:A29"," A32:A37"它给了我编译错误。
有人有答案吗?