0
如果AG_Label = M_Label,代碼將運行並粘貼,但僅限於第一個實例。 我的循環有問題,但我對VBA很新,所以我不知道如何解決它。VBA循環錯誤。只粘貼一個結果
Dim mrow As Long, ARow As Long, iRows As Long, srow As String
Dim x As Long, j As Long, i As Long
Dim AG_Label As String, AG_val As String, SNL_val As String, SNL_Label As String, M_Label As String, Rng As Range
Dim Vval As Long, Speriod As String, aperiod As String
Dim Count As Integer, Ajay As Variant
Count = 2
ARow = Sheets("AG").Range("A" & Rows.Count).End(xlUp).Row
Do
For i = 2 To ARow
AG_Label = Sheets("AG").Cells(i, "N").Value
'mrow = Sheets("Mappings").Range("A" & Rows.count).End(xlUp).Row
'For j = 2 To mrow
'M_Match_1 = Sheets("Mappings").Cells(j, "P").Value
M_Label = Sheets("Mappings").Cells(Count, "C").Value
If AG_Label = M_Label And Sheets("Mappings").Cells(Count, "L").Value = "FRY-9C" Then
Sheets("Mappings").Cells(Count, "J").copy
Sheets("AG").Cells(i, "AM").PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
On Error Resume Next
End If
Application.CutCopyMode = False
Next
'i = i + 1
Loop Until i = ARow + 1
Count = Count + 1
End Sub
對於初學者來說,解決這個線 - 'AROW =表(「公司」)範圍(「A」和Rows.Count).END (xlUp).Row'有一個像這樣的行的限定引用 - 'ARow = Sheets(「AG」)。Range(「A」&Sheets(「AG」).Rows.Count).End(xlUp).Row' – braX
您的'Count = Count + 1'緊挨在'End Sub'看起來可疑之前 - 絕對沒有任何一點遞增過程級變量,然後通過退出p來丟棄它rocedure。這應該在你的循環裏面嗎? – YowE3K
註釋掉'On Error Resume Next',除非有很好的理由。 –