我是VBA中的新成員。我想隱藏任何行的所有行到頁尾的結束。 我有它的問題是我不知道如何編程來隱藏最後一個書面行。 我使用下一個函數來了解最後寫入的單元格,但我不知道在哪裏放置Hide Function。隱藏/取消隱藏最後寫入的行
last = Range("A100000").End(xlUp).Row
非常感謝,任何幫助將不勝感激。
我是VBA中的新成員。我想隱藏任何行的所有行到頁尾的結束。 我有它的問題是我不知道如何編程來隱藏最後一個書面行。 我使用下一個函數來了解最後寫入的單元格,但我不知道在哪裏放置Hide Function。隱藏/取消隱藏最後寫入的行
last = Range("A100000").End(xlUp).Row
非常感謝,任何幫助將不勝感激。
試試這個,它將查找colA中的最後一個值,並將A1中的所有行放到LastRow中隱藏。
Sub test()
'Hides all rows with data
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("A1:A" & LastRow).EntireRow.Hidden = True 'to unhide set to False
'Hides last row until the end of the sheet
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
Range("B" & LastRow + 1 & ":B1048576").EntireRow.Hidden = True 'to unhide set to False
'Hides last row + 1 until the end of the sheet
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
Range("B" & LastRow + 1 & ":B1048576").EntireRow.Hidden = True 'to unhide set to False
End Sub
對代碼額外的信息
比方說,我們從A1的數據,直到A10
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
'we use this to get the lastrow number, in this case it will be 10
'the code is variable, so if we add data until A15, lastrow will become 15
Range("A1:A" & LastRow)
'this is the range that will be hidden A1 until A10
你能;
Dim startRow As Long: startRow = 10
Dim lastRow As Long: lastRow = ActiveSheet.UsedRange.Rows.Count
ActiveSheet.Rows(startRow & ":" & lastRow).Hidden = True
如果隱藏,則不包括最後一行 – Hogan
它的作品真的很好,但問題是,我想從最後寫入單元格藏 - >在紙張上的最後一個單元格,但是這個代碼隱藏,就像你說的,從單元格A1 - - >到最後寫的。我不明白「代碼」「A1:A」,它是如何工作的? – themolestones
哦,我的壞,你想要另一種方式嗎?那麼讓我們說A10是最後一行,你想隱藏A10行到最後? – CustomX
@themolestones,檢查我編輯的答案。 – CustomX