-1

嗨,我的问题是,当代码搜索 (i, 1) 以查找“Hello”时,它会找到它但不会将其发送到 WSS,而且我越看越沮丧,有人可以帮忙吗

Sub AddSelection()

Dim WSD As Worksheet ' Sheet 1 as prices sheet
Dim WSW As Worksheet ' Workings sheet as Information
Dim WSS As Worksheet ' Selections worksheet

Set WSD = Worksheets("Selection")
Set WSW = Worksheets("Workings")
Set WSS = Worksheets("Selections")

' Loop through records on WSD column A

FinalRow = WSD.Cells(Rows.Count, 1).End(xlUp).Row
    For i = 5 To FinalRow
        If WSD.Cells(i, 1) = "Hello" Then


        ' When I run the code this where the problem is
        WSD.Cells(i, 1).Copy Destination:=WSS.Cells(NextRow, 4)


        NextRow = NextRow + 2

        FinalRow = WSS.Cells(Rows.Count, 1).End(xlUp).Row

    End If
Next i

'Make sure WSR is the active sheet
WSS.Select


' Report that the macro is done
MsgBox prompt:=NextRow - 1 & " Results Records Are Copied To Worksheet."


End Sub
4

1 回答 1

4

NextRow从未定义。您需要在使用它之前定义它。

要停止犯这个错误,请在 VBA 项目中每个“文件”的顶部写下:

Option Explicit

于 2013-08-07T23:25:27.063 回答