我有这个代码可以找到一个特定的单元格,然后将事件单元格设置在它的右侧。
但是,我想让它找到其中包含苹果和香蕉的单元格,而是使事件单元格成为与原始发现的苹果和香蕉单元格所在的同一行的最后使用列中的单元格。
我希望这是有道理的,我感谢任何帮助。
谢谢。
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/