Reputation: 19
I am trying to copy data from one sheet to another in the same workbook based on a cell value: below is my code, however it gives me an application 1004 error when compiling and i do not have a clue. please he;lp
Sub COPY1()
Dim lROW As Integer
Dim rngFrom, rngTo As Range
Sheets("LEL2230K").Activate
lROW = Sheets("LEL2230K").Cells(Rows.Count, "C").End(xlUp).Row
Set rngFrom = Sheets("LEL2230K").Range(Cells(6, "C"), Cells(lROW, "C"))
Sheets("MASTER").Activate
Set rngTo = Sheets("Master").Range(Cells(7, "A"), Cells(lROW, "A"))
rngFrom.Copy rngTo
End Sub
Upvotes: 0
Views: 95
Reputation: 38
I created two sheets with same names.
I put in sheet "LEL2230K" address C6:C9 some data: "DATA1", "DATA2", "DATA3", "DATA4"
When I run your macro, everything works fine. But I make some changes in your code, try it:
Sub COPY1()
Dim LEL2230K, MASTER As Worksheet
Set LEL2230K = ThisWorkbook.Sheets("LEL2230K")
Set MASTER = ThisWorkbook.Sheets("MASTER")
LEL2230K.Range(LEL2230K.Cells(6, "C"), LEL2230K.Cells(LEL2230K.Cells(LEL2230K.Rows.Count, "C").End(xlUp).Row, "C")).Copy
MASTER.Cells(7, "A").PasteSpecial
End Sub
I highly recommend you to name sheet objects in it properties and use it name as reference.
Upvotes: 1