0

I am trying to go through worksheet(PasteHere) and match the name with worksheet(Breakdown). When the two name matches, I need to copy the range from worksheet(PasteHere) and paste into worksheet(Breakdown). For some reason I am getting a run time error that does not allow me to use the current range to copy and paste.

Sub Stats()

Dim Row As Integer
Dim RowP As Integer
Dim Col As Integer

For Row = 2 To 200
    For RowP = 2 To 200
        If Worksheets("PasteHere").Cells(RowP, 2) = Worksheets("Breakdown").Cells(Row, 2) Then 
            Worksheets("PasteHere").Range("IRowP:CRRowP").Copy Worksheets("Breakdown").Range("IRow:CRRow")
        End If    
    Next RowP
Next Row

MsgBox "Done"

End Sub
Tim Stack
  • 3,209
  • 3
  • 18
  • 39
codeda123
  • 1
  • 1
  • 5
    `Range("I" & RowP & ":CR" & RowP)`, and `Range("I" & Row & ":CR" & Row)`. I'm sure there's a duplicate question somewhere here on SO :) – BigBen Oct 28 '19 at 15:07

1 Answers1

0

Dim Row As Integer
Dim RowP As Integer
Dim Col As Integer

For Row = 2 To 200
    For RowP = 2 To 200
        If Worksheets("PasteHere").Cells(RowP, 2) = Worksheets("Breakdown").Cells(Row, 2) Then 
            Worksheets("PasteHere").Range("I" & RowP & ":CR" & RowP).Copy Worksheets("Breakdown").Range("I" & Row & ":CR" & Row)
        End If    
    Next RowP
Next Row

MsgBox "Done"

End Sub

When you use the Row and RowP variables you have to jump out of the double quote vba string and use the & character to concat.

Wilco
  • 374
  • 1
  • 11