L
Legacy 316950
Guest
Hello everyone. I wrote this code to copy spefic values from Sheet2 to Sheet1. But i don't know how to use loop properly in VBA, and i don't know how to paste these values.
Here is my code. I know it's not a very smart code, but i'm new on VBA, if anyone see a tip to give me, i will be very grateful.
Here is my code. I know it's not a very smart code, but i'm new on VBA, if anyone see a tip to give me, i will be very grateful.
Code:
Sub compare_copy_paste()
'Declaration of variables
Dim d1 As Range
Dim base As Rangge
Dim copia As Range
'Range that i don't know how to use in the loop
Sheets("Sheet1").Select
Set d1 = Range("A6:A600")
d1.Select
Sheets("Sheet2").Select
Set base = Range("B2:B700")
base.Select
'Loop with problems, when the macro is running is like a infinite loop.
For i = 6 To 700
For j = 1 To 700
If Worksheets("Sheet1").Cells(i, 1).Value = Worksheets("Sheet2").Cells(i, 2) Then
Worksheets("Sheet2").Cells(i, 11).Copy
Worksheets("Sheet1").Select
Worksheets("Sheet1").Cells(i, 5).Paste
End If
Next j
Next i
End Sub
Last edited by a moderator: