2016-11-28 72 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)上,我想找到在我提到的范围内的活动行上的下一个空单元。 –

相关问题