[vba] Run-Time error '1004'- Method 'Range' of object '_global' failed

ajamess

Board Regular
Joined
Sep 13, 2016
Messages
92
I'm getting an error on a vba code I'm trying to write.

For i = 1 To 8
Range(Cells(2, i + 1), Cells(lastrow1, i + 1)).Select
Selection.Copy
Workbooks("Querypartlist.xlsx").Activate
Range(Cells(1 + lastrow1 * (i - 1), 1)).Select (THIS IS SPECIFICALLY HIGHLIGHTED LINE)
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Workbooks("Parts.xlsx").Activate

Next

The bolded line is the one I am having errors with. I can't figure out what the issue is. Up on the first line it can find a very similar range, the only difference is I've added the lastrow1(which is a long number). Anybody know what mistake I'm making?
 
Last edited by a moderator:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Does this work?
Code:
For i = 1 To 8
    Range(Cells(2, i + 1), Cells(lastrow1, i + 1)).Copy
    Workbooks("Querypartlist.xlsx").ActiveSheet.Cells(1 + lastrow1 * (i - 1), 1).PasteSpecial Paste:=xlPasteValue

Next I
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,025
Messages
6,128,356
Members
449,444
Latest member
abitrandom82

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top