[英]excel vba toggle hide/unhide range rows across multiple sheets, if cell value 0
我希望下面的工作跨頁“摘要”,“W1”,“W2”,“W3”,“W4”,“W5”,但我面臨一些問題,你能幫忙嗎?
代碼是隱藏上面工作表中的空行,以隱藏未使用的行。 以上范圍在所有上述片材中是相同的。 該按鈕用於切換隱藏/取消隱藏行。
謝謝!
鏈接到我的文件: 我的工作簿
Private Sub CommandButton1_Click()
If CommandButton1.Caption = "Less Rows" Then
CommandButton1.Caption = "More Rows"
Else
CommandButton1.Caption = "Less Rows"
End If
On Error Resume Next
With Range("a8:a91,a96:a121").SpecialCells(xlBlanks).EntireRow
.Hidden = Not .Hidden
End With
On Error GoTo 0
End Sub
這將循環遍歷范圍中的所有行並檢查值,並循環遍歷工作簿中的所有工作表。
Private Sub CommandButton1_Click()
Dim rng As Range
Dim iRow as Range
Dim wsh As Worksheet
Dim hidden_status As Boolean
If CommandButton1.Caption = "Less Rows" Then
CommandButton1.Caption = "More Rows"
Else
CommandButton1.Caption = "Less Rows"
End If
On Error Resume Next
For Each wsh in ThisWorkbook.Worksheets
Set rng = wsh.Range("A8:A91,A96:A121")
For Each iRow in rng.Rows
If iRow.Value = "" Then
With iRow.EntireRow
hidden_status = .Hidden
.Hidden = Not hidden_status
End With
End If
Next iRow
Next wsh
On Error GoTo 0
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.