MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Jan 14th, 2002, 04:21 PM   #1
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

To answer part 1.

OK, usually using "Select" is a huge giveaway when you're trying to speed up macros. Selecting worksheets can take a second.

In the middle of your code you have:


ws.Select
ActiveSheet.PageSetup.PrintArea = Range("A1", Range("H65536").End(xlUp)).Address

With ActiveSheet.PageSetup


I would suggest changing these lines to:


With ActiveSheet.PageSetup
.PageSetup.PrintArea = Range("A1", Range("H65536").End(xlUp)).Address


I've not tested the code and I don't know if you can perform the operations that you want to do without the sheet being active, but this is worth a shot.

HTH
Mark O'Brien is offline   Reply With Quote
Old Apr 12th, 2002, 03:56 PM   #2
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

Created code to fit certain worksheet to fit to 1 page wide and 1 page tall.

Here's my code. Had it exclude certain worksheets. But it takes a couple of seconds for each worksheet. Is because it's looping though the excluding certain worksheets part? How can I get it to exclude them once and for all and then set print areas for all other sheets??

Also, I want to just set the print area to print on ONE page only.
Can I just use only

.FitToPagesWide = 1
.FitToPagesTall = 1

and exclude the rest?
From .LeftHeader = ""
to .Zoom = False

THANKS!

CODE:
For Each ws In Worksheets
If ws.Name <> "Summary" Then
If ws.Name <> "Test" Then
If ws.Name <> "Test2" Then
If ws.Name <> "Test3" Then
If ws.Name <> "Test4" Then
If ws.Name <> "Test5" Then
ws.Select
ActiveSheet.PageSetup.PrintArea = Range("A1", Range("H65536").End(xlUp)).Address

With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.75)
.RightMargin = Application.InchesToPoints(0.75)
.TopMargin = Application.InchesToPoints(1)
.BottomMargin = Application.InchesToPoints(1)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlPortrait
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With

End If
End If
End If
End If
End If
End If

Next ws
End Sub

[ This Message was edited by: Cosmos75 on 2002-04-15 10:44 ]
Cosmos75 is offline   Reply With Quote
Old Apr 15th, 2002, 10:06 AM   #3
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

So, it's the ws.select that is making it slow and not this part?

For Each ws In Worksheets
If ws.Name <> "Summary" Then
If ws.Name <> "Test" Then
If ws.Name <> "Test2" Then
If ws.Name <> "Test3" Then
If ws.Name <> "Test4" Then
If ws.Name <> "Test5" Then

Is there a way to have it exclude those sheets only once instead of checking each shet to see if it's those 6 sheets to be excluded? (Or is it already doing that?)

Cosmos75 is offline   Reply With Quote
Old Apr 15th, 2002, 10:35 AM   #4
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default

I believe that the slow part is the formatting. VBA is very slow in this, compared to Excel4 macros, or so I've read.

Try to quicken the formatting part by getting rid of the default values that you are not changing anyway.

Mark's suggestions also will help a lot. I'll address your other question after (if) I figure it out.

Bye,
Jay
Jay Petrulis is offline   Reply With Quote
Old Apr 15th, 2002, 10:38 AM   #5
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

Thanks, Jay!
Cosmos75 is offline   Reply With Quote
Old Apr 15th, 2002, 10:39 AM   #6
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

Sorry, I gave you a bit of misinformation there, I told you to use:


With ActiveSheet.PageSetup
.PageSetup.PrintArea = Range("A1", Range("H65536").End(xlUp)).Address


What you should use is:


With ws.PageSetup
.PageSetup.PrintArea = Range("A1", Range("H65536").End(xlUp)).Address


Those "If" statements shouldn't really be slowing you down too much. I can't really think of an easy way to only run this check once. However, one thing I would suggest is having a look at "Select Case" instead of the "If...Then" statements. e.g.:


Dim ws As Worksheet


For Each ws In Worksheets
Select Case ws.Name

Case "Test", "Test2", "Test3" '....etc, complete this yourself
'Do nothing
Case Else
'Your Code here
End Select

Next


The reason being is that "Select Case" is usually faster than several "If..Then" statements.

HTH

_________________
[b] Mark O'Brien

[ This Message was edited by: Mark O'Brien on 2002-04-15 09:40 ]
Mark O'Brien is offline   Reply With Quote
Old Apr 15th, 2002, 10:47 AM   #7
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

Mark O'Brien,

Thanks, will try that out! Am learning more and more each day!
Cosmos75 is offline   Reply With Quote
Old Apr 15th, 2002, 11:00 AM   #8
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

Mark O'Brien,

Changed your

With ws.PageSetup
.PageSetup.PrintArea = Range("A1", Range("H65536").End(xlUp)).Address

to this (removed repeated .PageSetup)

With ws.PageSetup
.PrintArea = Range("A1", Range("H65536").End(xlUp)).Address

I tried this

With ws.PageSetup
.PrintArea = Range("A1", Range("H65536").End(xlUp).Address)
.Orientation = xlPortrait
.FitToPagesWide = 1
.FitToPagesTall = 1
End With

Doesn't work. Error with

.PrintArea = Range("A1", Range("H65536").End(xlUp).Address)

Haven't tried the case part yet...
Cosmos75 is offline   Reply With Quote
Old Apr 15th, 2002, 11:04 AM   #9
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

Oh yeah and you're going to have to qualify the ranges now. i.e. reference them fully. So in this case you want to put:


.PrintArea = ws.Range("A1", ws.Range("H65536").End(xlUp).Address)


We'll get this sorted. I promise.

I just had a quick look a the code and I think this is the only line that should need this.
_________________
[b] Mark O'Brien

[ This Message was edited by: Mark O'Brien on 2002-04-15 10:04 ]
Mark O'Brien is offline   Reply With Quote
Old Apr 15th, 2002, 11:32 AM   #10
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

Mark O'Brien,

I am so sorry for this trouble but it isn't working.

I get a error message

Run-time error '13':
Type mismatch

With ws.PageSetup
.PrintArea = ws.Range("A1", ws.Range("H65536").End(xlUp).Address)
Cosmos75 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 09:16 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes