Excel 隐藏/取消隐藏上次写入的行

Excel 隐藏/取消隐藏上次写入的行,excel,vba,Excel,Vba,我是VBA新手。我想隐藏或取消隐藏从任何一行到工作表末尾的所有行。 我的问题是我不知道如何编程来隐藏最后一行。 我使用next函数来知道最后写入的单元格,但我不知道隐藏函数的位置 last = Range("A100000").End(xlUp).Row 非常感谢,任何帮助都将不胜感激。尝试此操作,这将查找colA中的最后一个值,并将从A1到最后一行的所有行都隐藏起来 Sub test() 'Hides all rows with data LastRow = Cells(Row

我是VBA新手。我想隐藏或取消隐藏从任何一行到工作表末尾的所有行。 我的问题是我不知道如何编程来隐藏最后一行。 我使用next函数来知道最后写入的单元格,但我不知道隐藏函数的位置

last = Range("A100000").End(xlUp).Row

非常感谢,任何帮助都将不胜感激。

尝试此操作,这将查找colA中的最后一个值,并将从A1到最后一行的所有行都隐藏起来

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

它工作得非常好,但问题是我想从最后一个写入的单元格-->隐藏到工作表上的最后一个单元格,但正如您所说,这段代码从单元格A1-->隐藏到最后一个写入的单元格。我不明白“代码”A1:A,它是怎么工作的?哦,糟糕,你想让它反过来吗?假设A10是最后一行,是否要将第A10行隐藏到结尾?如果最后一行被隐藏,则不包括该行。如果最后一行被隐藏,则不包括该行