VBA Error - Run-time error '1004' - Method 'Range of object'_Global' failed

ststern45

Well-known Member
Joined
Sep 17, 2005
Messages
989
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
The following code I am trying to copy a custom range of date from 1 workbook worksheet back to another workbook worksheet.
Pick3Drawings workbook worksheet PA3E (samename1) is where I am trying to copy the custom range of data to LM3Step1A workbook worksheet P3Draws.
Custom range is Cell A20 through E8953 (Note: this range will change each day)

Thank you in advance

Sub CopyPastep3Data()

Dim aRng As String, Sname1 As String
Dim bRng As String
Dim cRng As Integer
Dim dRng As Integer

Application.ScreenUpdating = False

Windows("LM3Step1A.xlsm").Activate

Sheets("P3Draws").Select

aRng = Sheets("P3Draws").Range("K2").Value 'Column A
bRng = Sheets("P3Draws").Range("O2").Value "Column E

cRng = Sheets("P3Draws").Range("B18").Value 'Cell value =20
dRng = Sheets("P3Draws").Range("B19").Value 'Cell value = 8953

Sname1 = Sheets("P3Draws").Range("B14").Value 'Worksheet name = PA3E


Windows("Pick3DRawings.xlsm").Activate


Sheets(Sname1).Select 'PA3E Worksheet
Range(aRng & Range(cRng).Value & ":" & bRng & Range(dRng).Value).Copy _ 'Cell range A20:E8953

' Code above is where I receive the error

Windows("LM3Step1A.xlsm").Activate

Sheets("P3Draws").Select
Range("K20").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Range("E2").Select

Application.ScreenUpdating = True


End Sub
 
What exactly are the values in Sheets("P3Draws").Range("K2") and Sheets("P3Draws").Range("O2").Value?

Range(cRng).Value should just be cRng and Range(dRng).Value should just be dRng
 
Upvote 0
1. Change
VBA Code:
Range(aRng & Range(cRng).Value & ":" & bRng & Range(dRng).Value).Copy
to
VBA Code:
Range(aRng & cRng & ":" & bRng & dRng).Copy

2. ACTIVATE, SELECT are not needed

VBA Code:
Sub CopyPastep3Data()

Dim aRng As String, Sname1 As String
Dim bRng As String
Dim cRng As Integer
Dim dRng As Integer

    Application.ScreenUpdating = False
    
    With Workbooks("LM3Step1A.xlsm").Worksheets("P3Draws")
        aRng = .Range("K2").Value   '    Column A
        bRng = .Range("O2").Value   '    Column E
        cRng = .Range("B18").Value          '   Cell value =20
        dRng = .Range("B19").Value          '   Cell value = 8953
        Sname1 = .Range("B14").Value      '   Worksheet name = PA3E
    End With
    
    Workbooks("Pick3DRawings.xlsm").Worksheets(Sname1).Range(aRng & cRng & ":" & bRng & dRng).Copy
    Workbooks("LM3Step1A.xlsm").Worksheets("P3Draws").Range("K20").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Thank you everyone for all your help.
The updated code works great.
Thank you!!
 
Upvote 0

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