![](/img/trans.png)
[英]Vba to find first empty cell and average the 4 cells above it and paste value in another cell
[英]Use the Find function in VBA to find the first value above the active cell?
我正在嘗試獲取查找功能的結果的行號,我正在使用以下內容。
Set FindRow = ThisWorkbook.Sheets("Schedule").Range(ActiveCell.Address & ":n" & Sheets("Schedule").Cells(ActiveSheet.Rows.Count, 1).End(XlUP).Row).Find(What:="Assembly", SearchDirection:=xlPrevious, MatchCase:=False)
Msgbox (FindRow.Row)
這可以正常工作,但返回其中包含值的范圍中的最后一個單元格。 如果將“搜索方向”更改為XlNext,這將返回下面的下一個單元格,其中包含值。 我希望它在活動單元格上方搜索下一個值。
認為您只需要指定After參數即可。 編輯-根據活動單元的反射情況,您要搜索的范圍可以是任意大小,因此您需要解釋“活動單元上方”的含義。
Sub x()
Dim FindRow As Range, r As Range
With ThisWorkbook.Sheets("Schedule")
Set r = .Range(ActiveCell.Address & ":N" & .Cells(.Rows.Count, 1).End(xlUp).Row)
Set FindRow = r.Find(What:="Assembly", after:=r(r.Cells.Count), SearchDirection:=xlNext, MatchCase:=False)
End With
If Not FindRow Is Nothing Then MsgBox (FindRow.Row)
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.