I am working on a macro that used columns as number (i.e. A=1, B=2) in the VBA code and I am trying to see if I can simplified my code to copy the value of a range from another worksheet to a range on a specified worksheet. Both range are identical in size.
I was able to first get it to work within the same worksheet with this code:
Range(Cells(1, 1), Cells(1, 4)).Value = Range(Cells(1, 10), Cells(1, 13)).Value 'working
But then I thought I could just do the below code and it would work with a range in another worksheet but I got an error (run-time error 9 subscript out of range):
Sheets("Sheet1").Range(Cells(1, 1), Cells(1, 4)).Value = Sheets("Sheet2").Range(Cells(1, 10), Cells(1, 13)).Value 'Not Working
I search the web and ultimately came up with the code below that works but I was wondering if it can simplified to a one liner similar to the code above?
'Working
Sheets("Sheet2").Activate
ActiveSheet.Range(Cells(1, 10), Cells(1, 13)).Copy
Sheets("Sheet1").Activate
Range(Cells(1, 1), Cells(1, 4)).Select
ActiveSheet.Paste
Thank you for your time!
Bookmarks