copy to range problem

zpierucci

New Member
Joined
Sep 5, 2019
Messages
42
Code:
Sub checkwood()
Dim i As Integer
Dim r2 As Integer
Dim lastrow1 As Long
Dim woodcoasters As Range


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




   For i = 2 To lastrow1
   
    r2 = 2
        If Cells(i, 3).Value = Cells(14, 3).Value Then
           Range("A" & i).Copy Range("j" & r2)
           
          r2 = 2 + 1
           
        End If
           
    Next i
    


End Sub
[code/]

trying to get values to paste into column J if the cells in column C for the criteria. All values are pasting into J2 and not moving down
??
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Try it like
Code:
R2 = 2
For i = 2 To Lastrow1
   If Cells(i, 3).Value = Cells(14, 3).Value Then
      Range("j" & R2).Value = Range("A" & i).Value
      R2 = R2 + 1
   End If
Next i
 
Upvote 0
Perfect. What was the main problem with original code? I need to declare r2 value outside of If Loop and?
 
Upvote 0
There were two problems, this line
Code:
r2 = 2 + 1
will simply make R2=3 every time through the loop, but that will then be overwritten because the first line line inside the loop set R2 back to 2.
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,587
Messages
6,120,405
Members
448,958
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top