簡體   English   中英

從活動單元格中查找空單元格

[英]Find Empty Cell from activecell in a range

這里的新手需要幫助,以找到來自activecell.row。范圍內的下一個空單元格。

Sub FindNextCell()
'
'Macro1 Macro

Cells.Find(What:="", _
             After:=Range("F2:I22")(Cells(ActiveCell.Row, _
             Columns.Count).End(xlToLeft).Offset(0, 1)), _
             LookIn:=xlFormulas, LookAt:=xlPart, _
             SearchOrder:=xlByRows, _
             SearchDirection:=xlNext, _
             MatchCase:=False, _
             SearchFormat:=False).Activate
End Sub

使用Find方法時,最好將結果設置為Range

當然, Find可能不返回任何結果(以防在指定范圍內找不到另一個空單元格),這就是為什么我們添加If Not EmptyRng Is Nothing Then

Option Explicit

Sub FindNextCell()

Dim FindRng As Range, EmptyRng As Range

' define the Range to search according to ActiveCell current row
Set FindRng = Range("F" & ActiveCell.Row & ":I" & ActiveCell.Row)

' COMMENT : need to cheat a little to get the first cell founds in the searched range
'           by starting from the last column in the range, Column "I"
'           Otherwise, will return the second cell found in the searched range
Set EmptyRng = FindRng.Find(What:="", after:=Cells(ActiveCell.Row, "I"), _
                            LookIn:=xlValues, lookat:=xlWhole)

' found an empty cell in the specified range
If Not EmptyRng Is Nothing Then
    EmptyRng.Select
Else ' unable to find an empty cell in the specified range
    MsgBox "Unable to find an empty cell in " & FindRng.Address & " Range"
End If

End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM