gpt4 book ai didi

excel - 事件单元格查找行中的最后一列 vba

转载 作者:行者123 更新时间:2023-12-04 22:30:28 26 4
gpt4 key购买 nike

我有这个代码可以找到一个特定的单元格,然后将事件单元格设置在它的右侧。

但是,我想让它找到其中包含苹果和香蕉的单元格,而是使事件单元格成为与原始发现的苹果和香蕉单元格所在的同一行的最后使用列中的单元格。

我希望这是有道理的,我感谢任何帮助。

谢谢。

Cells.Find(What:="Apples and Banana", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Select

最佳答案

您可以在 find 的帮助下找到单元格的行来完成。和 .row然后在激活单元格之前检查最后一列。

Option Explicit

Sub test()

Dim LastCol As Long
Dim ABRow As Long
Dim ABrange As Range

Set ABrange = Cells.Find(What:="Apples and Banana", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False)

If Not ABrange Is Nothing Then
ABRow = ABrange.Row
End If

LastCol = Cells(ABRow, Columns.Count).End(xlToLeft).Column

Cells(ABRow, LastCol).Activate

End Sub

关于excel - 事件单元格查找行中的最后一列 vba,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53297482/

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