gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 20:19:09 29 4
gpt4 key购买 nike

我是 VBA 新手。我想隐藏从任何行到工作表末尾的所有行。
我遇到的问题是我不知道如何编程以隐藏最后写入的行。
我使用下一个函数知道最后写入的单元格,但我不知道在哪里放置隐藏函数。

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

关于excel - 隐藏/取消隐藏最后写入的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13251534/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com