gpt4 book ai didi

vba - excel vba选择最后一行和最后一列

转载 作者:行者123 更新时间:2023-12-04 21:34:05 25 4
gpt4 key购买 nike

我正在尝试从 A9 中进行选择到lastrow & lastcolumn .

我有这个来选择最后一个单元格,但它没有从 A9 to Last 中选择它只是选择 lastrow/lastcolumn。这也不理想,因为如果我将来有空白。

我已经搜索并找不到任何可以从单元格中选择到 lastrow & lastcolumn 的内容。

Sub FindLast()
Application.ScreenUpdating = False

Range("A9").End(xlToRight).End(xlDown).Select

Application.ScreenUpdating = True
End Sub

我文件中的搜索顺序为列 A & 行 8如果这有帮助的话。

Code Below is what I am using to work on active sheets


Sub SelectAll()
Application.ScreenUpdating = False

Dim lastRow As Long, lastCol As Long
Dim Rng As Range
Dim WholeRng As Range

With ActiveWorksheet
Set Rng = Cells

'last row
lastRow = Rng.Find(What:="*", After:=Rng.Cells(1), Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row

'last column
lastCol = Rng.Find(What:="*", After:=Rng.Cells(1), Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False).Column

Set WholeRng = Range(Cells(9, "A"), Cells(lastRow, lastCol))
WholeRng.Select
End With

Application.ScreenUpdating = True
End Sub

最佳答案

或者你可以利用 UsedRange

Sub FindLast()
With Activesheet
.Range(.Range("A9"), .UsedRange.Cells(.UsedRange.Rows.Count, .UsedRange.Columns.Count)).Select
End With
End Sub

关于vba - excel vba选择最后一行和最后一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43353218/

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