Excel宏查询:根据单元格值隐藏行
嗨我已经尝试了下面的代码,但它似乎没有工作,任何人都可以帮助我。我只是想隐藏行3 & 4当B1有文字Delete
。但是我想在Delete
进入B1时自动运行。Excel宏查询:根据单元格值隐藏行
感谢
回答:
像这样的东西应该工作
Option Explicit 'Very first line to ensure that variables are declared Private Sub Worksheet_Change(ByVal Target As Range)
'check if target address is B1
If Target.Address(RowAbsolute:=False, ColumnAbsolute:=False) = "B1" Then
ShowHideRows
End If
End Sub
Public Sub ShowHideRows()
If Range("B1").Value = "Delete" Then
Rows("3:4").EntireRow.Hidden = True
Rows("7:8").EntireRow.Hidden = False
ElseIf Range("B1").Value = "Open" Then 'use ElseIf if possible like here
Rows("3:4").EntireRow.Hidden = False
Rows("7:8").EntireRow.Hidden = True
End If
End Sub
注:这是区分大小写的。所以如果你输入B1 delete
而不是Delete
它将不会运行。为使其不区分大小写,请使用LCase()
,例如:
LCase(Range("B1").Value) = "delete" 'string delete must be lower case!
以上是 Excel宏查询:根据单元格值隐藏行 的全部内容, 来源链接: utcz.com/qa/262158.html