Dynamic Print Area

ElEdwards

Board Regular
Joined
Aug 29, 2002
Messages
220
I've been searching this forum and have found just enough tidbits to get me on the road to frustration :biggrin:

Daily, I copy text (from another program) into Excel, remove some blanks, set the print area (the number of rows changes daily), copy this range into another sheet for sorting, then print both sheets.

I want to do all of this in a single vba macro. For "print_area", I tried setting a dynamic named range that 'refers to':
=OFFSET(Alpha!$C$4,0,0,MATCH("cg",Alpha!$C:$C)-0,5)
Then in my macro, I put the line:
ActiveSheet.PageSetup.PrintArea = "print_area"

When I run this, the following happens:
- the dynamic named range "print_area" becomes the actual values, replacing the formula I entered.
- "print_area" is always 12 rows shorter than the data.

My data is always 6 columns wide but the number of rows changes. Today, the numbers of rows is 278 but the "print_area" selection (using the method I described above) is 263 rows. I want the final print area to contain no blank rows since I copy this range and sort it on another sheet.

Any help is appreciated.

Thanks!!
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Two options. You can set the Print Area to something like $A:$I, and Excel will print the current used rows in those columns.

Two, you're already using the named range, print_area, wich is the one that Excel uses to store the print settings. That name should be local, that means, refers to the worksheet, and not global (Not available on all worksheets). To check what you're named range is selecting, click in the "Refers To" box, and you'll see some "marching ants", that will show you what is it refering to, that way, you can correct it.
 
Upvote 0
I really want my macro to determine the print area, which is what I guess I didn't say in my original post. How do I do that?

Thanks!
El Edwards
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,301
Members
449,078
Latest member
nonnakkong

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