Error 1004

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a sub on a worksheet calculate area and the sub has these 4 lines:

Sheets("Results").Select
Set Rng = Range("nonvalidreport")
ActiveSheet.PageSetup.PrintArea = Rng.Address
ActiveWindow.SelectedSheets.PrintPreview

The sub is not on this sheet. But I get an error 1004 on line 2. If I run
these 4 lines in a module it works, but I can't figure out how to call a sub
in a module from the area where I am. HELP!
 
If you're code is in a worksheet module, then those unqualified ranges will
refer to the worksheet that owns the code. And that worksheet may not have a
range named "nonvalidreport".

I'd use this:

with worksheets("Results")
'.select 'not necessary to select
set rng = .range("nonvalidreport")
.pagesetup.printarea = rng.address
.printout preview:=true
end with

or this:

worksheets("results").range("nonvalidreport").printout preview:=true

If I didn't really want to change the .pagesetup.printarea, then the one-liner
would be easier to understand (for me).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top