I am new to macro writing and I need some help.
I have one sheet and need to copy the columns and reorder them to paste into a software program.
- I want to copy A2 - the last data entry in column A and paste it into A1 on Sheet2
- I want to copy B2 - the last data entry in column A and paste it into K1 on Sheet2
- I want to copy C2 - the last data entry in column A and paste it into C1 on Sheet2
- I want to copy D2 - the last data entry in column A and paste it into D1 on Sheet2
- Then from Sheet 2, I want to copy A1:KXXXX (to the last entry in column A) and save it on the clipboard to paste into the other application
Here is my code, I have tried... (I know this is just for copying column A, but I got stuck there.)
Sub Copy()
aLastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
Range("A2" & aLastRow).Select
Selection.Copy
Sheets("Sheet2").Select
Range("A1").Select
ActiveSheet.Paste
End Sub
Thank you so much for your help! Jess
Try this instead. Given that you said you got an error with the paste code and I am still using that, I think you'll still have an error there. Post the error message. Hopefully we can figure that out.
My original answer is below here. You can disregard.
This should accomplish your first goal:
I copied all 4 columns at once since that would be much faster but it assumes the columns are the same length. If that isn't true you would need to copy one at a time.
The data should be in the clipboard at the end of the macro.
Edit: I removed "wsIn.Activate" since it isn't really needed. Edit 2: Oops! I just noticed you wanted the output in different columns. I'll work on it.
Generally you want to avoid
.Select
and.Paste
when copying values and rather copy by.value = .value
: