告诉find函数在第36行之后找到第一次出现?

时间:2014-04-28 07:49:40

标签: vba excel-vba excel

我有一个变量startingRow

startingRow = 36

我想使用Cells.Find函数来搜索第36行之后的第一行。我该如何做到这一点?

foundRow = wksDreamSheet.Cells.Find("Summa/Snitt", 36, , , xlByRows, xlNext).Row 

1 个答案:

答案 0 :(得分:2)

试试这个:

startingRow = 36
With wksDreamSheet
    Set rng = .Range(startingRow & ":" & .Rows.Count).Find("Summa/Snitt", , , , xlByRows, xlNext)
End With

或更可靠:

Dim rng As Range
startingRow = 36

With wksDreamSheet
    Set rng = .Range(startingRow & ":" & .Rows.Count).Find("Summa/Snitt", , , , xlByRows, xlNext)
End With
If Not rng Is Nothing Then
    foundRow = rng.Row
Else
    foundRow = 1 ' or any other number (or msgbox with error)
End If