嗨我的问题是当代码搜索(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
答案 0 :(得分:4)
NextRow
。您需要在使用它之前定义它。
要停止犯这个错误,请将其写在VBA项目中每个“文件”的顶部:
Option Explicit