2016-11-28 71 views
0

新手在這裏需要幫助找到從activecell.row一系列下一emptycell ....查找activecell空單元格範圍

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 
+0

嘗試的代碼如下 –

回答

0

當使用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 
+0

感謝夏嘉曦瑞士雷達表我的答案我要去嘗試一下今晚 –

+0

@TerranceMatthew讓我知道,如果它 –

+0

我忘了說我的活動單元格會在列(1)上,我想找到在我提到的範圍內的活動行上的下一個空單元。 –

相關問題