1

I am trying to copy a 4 columns with its data from GraphColumns sheet (has 2666 rows) to another sheet within the same workbook called Graph Data. I want to paste it at the last row of Graph Data which is 12155. My code is as follows:

Sub C_P()
Dim lastrow As Integer

lastrow = Range("A" & Rows.Count).End(xlUp).Row


LR = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
Range("A2:D" & LR).Copy Destination:=Sheets("Graph Data").Range("A12155")

End Sub 
  • My lastrow isn't doing anything which I am aware off. I just want the macro to paste the .Range("last row of Graph Data") at A12155 without me calling it because I'll need it for future data as we progress.
BigBen
  • 46,229
  • 7
  • 24
  • 40
  • You may have an issue with unqualified ranges. Have you checked the value of `LR`? It's also unclear why you have two last row variables (`lastrow` & `LR`) – urdearboy Feb 25 '21 at 16:59
  • Side note, [Change `Integer` to `Long`](https://stackoverflow.com/questions/26409117/why-use-integer-instead-of-long). – BigBen Feb 25 '21 at 17:01

1 Answers1

0

Maybe you are looking for something like:

Sub C_P()

'Declare worksheets and variables
Dim GD As Worksheet: Set GD = ThisWorkbook.Sheets("Graph Data")
Dim GC As Worksheet: Set GC = ThisWorkbook.Sheets("Graph Columns")
Dim lr As Long

'Determine Graph Columns Range Size & Copy
lr = GC.Range("A" & GC.Rows.Count).End(xlUp).Row
GC.Range("A2:D" & lr).Copy

'Paste in first blank row on Graph Data
GD.Range("A" & (GD.Range("A" & GD.Rows.Count).End(xlUp).Offset(1).Row)).PasteSpecial xlPasteValues

End Sub

If you are really pasting the data to the static row then you can change the last line to

GD.Range("A12155").PasteSpecial xlPasteValues
urdearboy
  • 14,439
  • 5
  • 28
  • 58
  • Thank you so much! It worked. I have a question, my date is being pasted as number. I inserted the following command and it does not seem like it is working Range("B:B").NumberFormat = "m/d/yyyy" any idea how can I fix this? – Nouran Abualam Feb 25 '21 at 17:22
  • I would look that up separately since it's a different question (one that has been asked and solved many times on this site). StackOverflow = 1 Question 1 Post. Helps others looking for help in the future find what they are looking for easier :) – urdearboy Feb 25 '21 at 17:23
  • 1
    What you shared looks right. It's likely the same issue as your original post. You did not qualify the range. What worksheet? If you don't tell VBA it reverts to assumptions of what sheet you are referring to and sometimes VBA is wrong. So, tell it exactly what sheet you want the format to apply to `Hint: GD` i.e. `GD.Range("B:B").....` – urdearboy Feb 25 '21 at 17:24
  • 1
    Thank you for the direction, hint, and help. I am new to using stack overflow so I appreciate your insight and will keep it for future reference. Thank you!!:) – Nouran Abualam Feb 25 '21 at 17:29