ShowAllData works when filtered, error code when all showing?

  • Thread starter StargateFanFromWork
  • Start date
S

StargateFanFromWork

I have a PRINT ALL macro with button on a sheet. There are 2 other print
macros each filtering the data by 2 criteria. The 3rd, however, is to print
the entire worksheet without filters and I put the ShowAllData code at the
beginning before doing the sort and bringing up the print dialogue box:\

ActiveSheet.ShowAllData
Application.Goto Reference:="R1C4"
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range("C2")
_
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=
_
False, Orientation:=xlTopToBottom
Range("B2").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Application.Dialogs(xlDialogPrint).Show

If the data is already in ShowAll mode, I get the usual 1004 error:

"Run-time error '1004':
ShowAllDate method of Worksheet class failed"

while the entire macro works fine if the sheet is filtered. How can I get
around the problem when it happens to _already_ show all the data, pls?

Thank you!
 
D

Dave Peterson

Here are a couple of ways:

on error resume next
activesheet.showalldata
on error goto 0

or

with activesheet
if .filtermode then
.showalldata
end if
end with
 
S

StargateFanFromWork

Dave Peterson said:
Here are a couple of ways:

on error resume next
activesheet.showalldata
on error goto 0

<dancing a jig, dancing a jig>

I love it! This is just soooo amazing! It worked beautifully. "Encasing"
the activesheet.showalldata command within the error structure is great. On
error, it resumes to goto 0, which means to me, basically DO NOTHING! <lol>

This is great!

Well, I'm getting close to the end of my contract and this particular
spreadsheet could only be better if it were written in Access. It has
pretty complete and comprehensive solution-type of functionality, something
I never would have believed of any spreadsheet program. I'm really
impressed <g>.

Thank you so much everyone for your help on this one. I don't think there's
anything left to do on this book, it's all pretty much just a question of
someone with enough basic knowledge to not screw anything up! <g> But
that's the last thing to tackle, protecting the sheet.

Cheers!
 
D

Dave Peterson

"on error goto 0" means to return control to excel's error handling instead of
one of your own.

(for what it's worth, I like the other way.)
 
S

StargateFan

"on error goto 0" means to return control to excel's error handling instead of
one of your own.

(for what it's worth, I like the other way.)

Yes? I must admit I didn't quite understand the other way and this
syntax was familiar enough to me. It does seem to work, however?
Will I have problems down the road having used the other code?
 
D

Dave Peterson

The only problem I see is if you forget to do the "on error goto 0" and leave
error checking completely off.
 

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

Top