gheyman
Well-known Member
- Joined
- Nov 14, 2005
- Messages
- 2,347
- Office Version
- 365
- Platform
- Windows
I am getting an error message when running this code
Run-time error '1004':
Select method of Range class failed
This is the line of code:
Sheets("DM Cost Source Details").Range("D2:E" & IDLR).Select
If I run this code separately it works fine, Its only when I inserted it into the above code did I start getting the error
Dim IDLR As Long
IDLR = Sheets("DM Cost Source Details").Cells(Rows.Count, "A").End(xlUp).Row
If IDLR > 2 Then
Sheets("DM Cost Sources").Range("D2:E2").Copy
Sheets("DM Cost Source Details").Range("D2:E" & IDLR).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End If
Any help is appreciated
Run-time error '1004':
Select method of Range class failed
This is the line of code:
Sheets("DM Cost Source Details").Range("D2:E" & IDLR).Select
Code:
Sub Execute()
'On Error Resume Next
'*********************************
'Hide Other Tabs
'********************************
Application.ScreenUpdating = True
Sheets("Step 1").Visible = xlSheetVeryHidden
Sheets("Step 2").Visible = xlSheetVeryHidden
Sheets("Step 3").Visible = xlSheetVeryHidden
Sheets("Step 4").Visible = xlSheetVeryHidden
Sheets("Step 5").Visible = xlSheetVeryHidden
Sheets("Step 7").Visible = xlSheetVeryHidden
Sheets("SSJ").Visible = xlSheetVeryHidden
Sheets("Parts").Visible = xlSheetVeryHidden
Sheets("Cost Sources").Visible = xlSheetVeryHidden
Sheets("Cost Source Details").Visible = xlSheetVeryHidden
Sheets("Vendors").Visible = xlSheetVeryHidden
Application.ScreenUpdating = False
UserForm3.Show vbModeless
UserForm3.LabelRetrieve.Width = 0
UserForm3.LabelTransform.Width = 0
UserForm3.LabelGenerate.Width = 0
UserForm3.LabelProg.Width = 20
UserForm3.LabelProg.Caption = "5%"
UserForm3.LabelRetrieve.Width = 48
DoEvents
Sheets("DM Parts").Visible = True
Sheets("DM Cost Sources").Visible = True
Sheets("DM Cost Source Details").Visible = True
Sheets("DM Vendors").Visible = True
Sheets("Other Tables").Visible = True
UserForm3.LabelProg.Width = 35
UserForm3.LabelProg.Caption = "10%"
DoEvents
'***********************************
'Run Query Refresh
'***********************************
'Refresh Query
With ThisWorkbook
Sheets("DM Parts").ListObjects(1).QueryTable.Refresh BackgroundQuery:=False
End With
UserForm3.LabelProg.Width = 45
UserForm3.LabelProg.Caption = "30%"
UserForm3.LabelTransform.Width = 54
DoEvents
'Refresh Query
With ThisWorkbook
Sheets("DM Cost Sources").ListObjects(1).QueryTable.Refresh BackgroundQuery:=False
End With
UserForm3.LabelProg.Width = 55
UserForm3.LabelProg.Caption = "35%"
DoEvents
'Refresh Query
With ThisWorkbook
Sheets("DM Cost Source Details").ListObjects(1).QueryTable.Refresh BackgroundQuery:=False
End With
UserForm3.LabelProg.Width = 60
UserForm3.LabelProg.Caption = "40%"
DoEvents
'Refresh Query
With ThisWorkbook
Sheets("DM Vendors").ListObjects(1).QueryTable.Refresh BackgroundQuery:=False
End With
UserForm3.LabelProg.Width = 65
UserForm3.LabelProg.Caption = "45%"
DoEvents
'Refresh Query
With ThisWorkbook
Sheets("Step 7").ListObjects(1).QueryTable.Refresh BackgroundQuery:=False
End With
UserForm3.LabelProg.Width = 75
UserForm3.LabelProg.Caption = "50%"
UserForm3.LabelGenerate.Width = 48
DoEvents
'Set the ID and Rev on both the DM Cost Sources and DM Cost Source Details
Dim IDLR As Long
IDLR = Sheets("DM Cost Source Details").Cells(Rows.Count, "A").End(xlUp).Row
If IDLR > 2 Then
Sheets("DM Cost Sources").Range("D2:E2").Copy
Sheets("DM Cost Source Details").Range("D2:E" & IDLR).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End If
'*****************************************************
' Clear Previous data from ProPricer Templates if any
'*****************************************************
'Clear Template
VLR = Sheets("Vendors").Cells(Rows.Count, "A").End(xlUp).Row
If VLR > 2 Then Sheets("Vendors").Range("A3:U" & VLR).ClearContents
UserForm3.LabelProg.Width = 80
UserForm3.LabelProg.Caption = "53%"
DoEvents
'Clear Template
CSLR = Sheets("Cost Sources").Cells(Rows.Count, "A").End(xlUp).Row
If CSLR > 2 Then Sheets("Cost Sources").Range("A3:AC" & CSLR).ClearContents
UserForm3.LabelProg.Width = 90
UserForm3.LabelProg.Caption = "59%"
DoEvents
'Clear Template
CSDLR = Sheets("Cost Source Details").Cells(Rows.Count, "A").End(xlUp).Row
If CSDLR > 2 Then Sheets("Cost Source Details").Range("A3:I" & CSDLR).ClearContents
UserForm3.LabelProg.Width = 100
UserForm3.LabelProg.Caption = "61%"
DoEvents
'Clear Template
PLR = Sheets("Parts").Cells(Rows.Count, "A").End(xlUp).Row
If PLR > 2 Then Sheets("Cost Source Details").Range("A3:AA" & PLR).ClearContents
UserForm3.LabelProg.Width = 110
UserForm3.LabelProg.Caption = "65%"
DoEvents
'*****************************************************
' Transfer data from DM tabs to ProPricer templates
'*****************************************************
'Transfer Data
Sheets("DM Parts").ListObjects("DM_Parts").DataBodyRange.Copy Sheets("Parts").Range("A3")
UserForm3.LabelProg.Width = 120
UserForm3.LabelProg.Caption = "70%"
DoEvents
'Transfer Data
Sheets("DM Cost Source Details").ListObjects("DM_Cost_Source_Details").DataBodyRange.Copy Sheets("Cost Source Details").Range("A3")
UserForm3.LabelProg.Width = 130
UserForm3.LabelProg.Caption = "72%"
DoEvents
'Transfer Data
Sheets("DM Cost Sources").ListObjects("DM_Cost_Sources").DataBodyRange.Copy Sheets("Cost Sources").Range("A3")
UserForm3.LabelProg.Width = 140
UserForm3.LabelProg.Caption = "73%"
DoEvents
'Transfer Data
Sheets("DM Vendors").ListObjects("DM_Vendors").DataBodyRange.Copy Sheets("Vendors").Range("A3")
UserForm3.LabelProg.Width = 150
UserForm3.LabelProg.Caption = "75%"
DoEvents
'**************************************************************************************************
Sheets("Parts").Visible = True
Sheets("Cost Sources").Visible = True
Sheets("Cost Source Details").Visible = True
Sheets("Vendors").Visible = True
Sheets("DM Parts").Visible = xlSheetVeryHidden
Sheets("DM Cost Sources").Visible = xlSheetVeryHidden
Sheets("DM Cost Source Details").Visible = xlSheetVeryHidden
Sheets("DM Vendors").Visible = xlSheetVeryHidden
Sheets("Other Tables").Visible = xlSheetVeryHidden
Sheets("Selected Parts List").Visible = xlSheetVeryHidden
UserForm3.Hide
Sheets("Step 6").Select
ActiveSheet.Shapes.Range(Array("Rounded Rectangle 1")).Select
Selection.ShapeRange.Fill.Visible = msoFalse
Range("F3").Select
MsgBox "Query has been succesfully executed. Please validate the data on the templates and then Export to ProPricer"
Application.ScreenUpdating = True
End Sub
If I run this code separately it works fine, Its only when I inserted it into the above code did I start getting the error
Dim IDLR As Long
IDLR = Sheets("DM Cost Source Details").Cells(Rows.Count, "A").End(xlUp).Row
If IDLR > 2 Then
Sheets("DM Cost Sources").Range("D2:E2").Copy
Sheets("DM Cost Source Details").Range("D2:E" & IDLR).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End If
Any help is appreciated