我正在尝试创建一个for循环,该循环查看G列中的数据,并根据其值将其剪切并将其粘贴到另一张纸上。我已经能够执行复制和粘贴,但是当我运行宏时,它将在n = 2时剪切并粘贴第3行,这导致跳过行。逐步执行代码n是正确的值,但似乎减少了n + 1。我暂时已删除的其他IF语句中使用了J,K和L。
谢谢
Dim n As Integer: n = 1
Dim i As Long: i = 1
Dim j As Long: i = 1
Dim k As Long: i = 1
Dim l As Long: i = 1
Dim newSheetName As String
Dim checkSheetName As String
ActiveSheet.UsedRange
Set r = ActiveSheet.UsedRange
nLastRow = r.Rows.Count + r.Row - 1
nFirstRow = r.Row
With ActiveSheet.UsedRange
For n = 1 To 20
If Cells(n, "D") <> "" Then
If Cells(n, "G") Like "*1492-J4*" Or Cells(n, "G") Like "*1492-J6*" Or Cells(n, "G") Like "*1492-J10*" Or Cells(n, "G") Like "*1492-JD4*" Or Cells(n, "G") Like "*1492-H*" Then
.Cells(n, "D").EntireRow.Cut Destination:=Worksheets("UCT-TM6").Range("A" & i)
'.Cells(n, "D").EntireRow.Delete
i = i + 1
Else
MsgBox "The part number " & Range("G" & n).Text & " does not exisit in database"
End If
End If
Next
End With