Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Applications > Excel, Macros, and Setting a Print Range...

Excel, Macros, and Setting a Print Range...
Thread Tools
Addicted to MacNN
Join Date: Mar 2001
Location: USA
Status: Offline
Reply With Quote
Jun 8, 2004, 12:58 PM
 
OK, everyone at the office is stumped, so I thought I'd see if there were any Excel wizards here to help us figure something out: how in the living cr@p can you get a macro to recognize the selected cells and set them as the print area?

If I have A1:Z100 selected, I want my macro to set those cells as the print area. If I have B3:C3 selected, I want my macro to set those cells as the print area, and so on, for any range I select.

If you record the process, you get something like this:
ActiveSheet.PageSetup.PrintArea = "$A$1:$U$112" — which is wrong b/c the range is hard-coded.

We need it to say something like:
ActiveSheet.PageSetup.PrintArea = "MyDadgumRangeSelection"

Nothing we do works, so any assistance would be appreciated!

TIA,
Maury
"Everything's so clear to me now: I'm the keeper of the cheese and you're the lemon merchant. Get it? And he knows it.
That's why he's gonna kill us. So we got to beat it. Yeah. Before he let's loose the marmosets on us."
my band • my web site • my guitar effects • my photos • facebook • brightpoint
     
Posting Junkie
Join Date: Nov 2001
Location: Retired.
Status: Offline
Reply With Quote
Jun 8, 2004, 01:25 PM
 
Will this work?

Start = Range("A1").Address
Finish = Range("P1").End(xlDown).Address

myPrintArea = Start & ":" & Finish

ActiveSheet.PageSetup.PrintArea = myPrintArea
     
Addicted to MacNN
Join Date: Mar 2001
Location: USA
Status: Offline
Reply With Quote
Jun 8, 2004, 03:02 PM
 
Originally posted by gorickey:
Will this work?

Start = Range("A1").Address
Finish = Range("P1").End(xlDown).Address

myPrintArea = Start & ":" & Finish

ActiveSheet.PageSetup.PrintArea = myPrintArea
Almost, but it's stopping at the row I have set to repeat at the top of all pages. Here's the macro in full:

Sub PageSetup()
'
' PageSetup Macro
' Macro recorded 6/8/2004 by Maury McCown
'

Start = Range("A1").Address
Finish = Range("U1").End(xlDown).Address
myPrintArea = Start & ":" & Finish
ActiveSheet.PageSetup.PrintArea = myPrintArea

With ActiveSheet.PageSetup
.PrintTitleRows = "$6:$6"
.PrintTitleColumns = ""
End With

With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.5)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = -4
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 100
End With
ActiveWindow.View = xlPageBreakPreview
ActiveSheet.VPageBreaks(1).DragOff Direction:=xlToRight, RegionIndex:=1
End Sub



Maury
"Everything's so clear to me now: I'm the keeper of the cheese and you're the lemon merchant. Get it? And he knows it.
That's why he's gonna kill us. So we got to beat it. Yeah. Before he let's loose the marmosets on us."
my band • my web site • my guitar effects • my photos • facebook • brightpoint
     
Posting Junkie
Join Date: Nov 2001
Location: Retired.
Status: Offline
Reply With Quote
Jun 8, 2004, 03:13 PM
 
     
Addicted to MacNN
Join Date: Mar 2001
Location: USA
Status: Offline
Reply With Quote
Jun 8, 2004, 03:33 PM
 
My wife, who works at the same company I do, came up with a solution:

Start = Range("A1").Address
Range("V1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, -1).Select
Selection.End(xlUp).Select
Finish = ActiveCell.Offset(1, 0).Address
myPrintArea = Start & ":" & Finish
ActiveSheet.PageSetup.PrintArea = myPrintArea

Since "V1" will always be empty, we can go to the last cell in that column, then move left one cell and up until you see a cell with content last cell in "U1"). For layout purposes, I then need to shift down 1 more cell, and the "Finish" cell is established.

I guess I'm cooking dinner tonight! Thanks for the macro ideas in your post, too, GR, as they've also been used to help with this.

Maury
"Everything's so clear to me now: I'm the keeper of the cheese and you're the lemon merchant. Get it? And he knows it.
That's why he's gonna kill us. So we got to beat it. Yeah. Before he let's loose the marmosets on us."
my band • my web site • my guitar effects • my photos • facebook • brightpoint
     
Posting Junkie
Join Date: Nov 2001
Location: Retired.
Status: Offline
Reply With Quote
Jun 8, 2004, 03:35 PM
 
Smart lady you got there...

     
Addicted to MacNN
Join Date: Mar 2001
Location: USA
Status: Offline
Reply With Quote
Jun 8, 2004, 04:53 PM
 
Originally posted by gorickey:
Smart lady you got there...

yes she is — and I forgot to explain why your code didn't work: there are blank cells in between data. Your method would only go as far as the last "full" cell, so the first empty one was stopping everything.

Thanks again,
Maury
"Everything's so clear to me now: I'm the keeper of the cheese and you're the lemon merchant. Get it? And he knows it.
That's why he's gonna kill us. So we got to beat it. Yeah. Before he let's loose the marmosets on us."
my band • my web site • my guitar effects • my photos • facebook • brightpoint
     
Posting Junkie
Join Date: Nov 2001
Location: Retired.
Status: Offline
Reply With Quote
Jun 8, 2004, 05:14 PM
 
Originally posted by RAILhead:
[B]yes she is — and I forgot to explain why your code didn't work: there are blank cells in between data. Your method would only go as far as the last "full" cell, so the first empty one was stopping everything./B]
Aww, gotcha...that makes sense!
     
   
Thread Tools
Forum Links
Forum 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 Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:23 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2