隐藏/取消隐藏最后写入的行

我是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