Error Run-time error '1004': select method of range class failed "cells select"

rjwatsoniii

New Member
Joined
Jan 27, 2009
Messages
2
When I click a button my macro errors out and indicates an issue with the line: "Cells.Select" below:

Any ideas:


Private Sub CommandButton1_Click()
'
Range("D7:D19").Select
Selection.Copy
Range("C7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ChDir "J:\Processing\"
Workbooks.Open Filename:="J:\Processing\_testamy\Amys CETO DOWNLD.xls"
Cells.Select
Application.CutCopyMode = False
Selection.QueryTable.Refresh BackgroundQuery:=False
ActiveWorkbook.Save
ActiveWindow.Close
ActiveWorkbook.Save
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End Sub

This is Excel 2003 SP3 on Windows XP SP2.

Thank you.

Rich
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
You need to qualify the sheet. Something like

Code:
ActiveSheet.Cells.Select
'
'or
'
Sheets("Sheet1").Cells.Select
 
Upvote 0
Rich

Why use it in the first place?:eek:

You also don't need this, as you use the full path name when you open the file.
Code:
ChDir "J:\Processing\"
Also all that use of ActiveWorkbook/Window/Select etc makes the code hard to follow.:)

And ActiveWorkbook.Save twice?:unsure:
 
Upvote 0
Thank you both for the fixes. Activesheet did the trick.

I just inherited the problem, I didn't create the macro. I am a systems guy not programming/macro dude.

Rich
 
Upvote 0
See if this works

Code:
Private Sub CommandButton1_Click()
With Range("D7:D19")
    .Value = .Value
End With
Workbooks.Open Filename:="J:\Processing\_testamy\Amys CETO DOWNLD.xls"
ActiveSheet.Cells.QueryTable.Refresh BackgroundQuery:=False
ActiveWorkbook.Save
ActiveWindow.Close
ActiveWorkbook.Save
ActiveSheet.PrintOut Copies:=3, Collate:=True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,533
Members
448,969
Latest member
mirek8991

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