macro for printing variable ranges

B

benoize

Hi all,

I'm writing a macro in which I need to print out a variable range. One
day it could be from A1:F10, the other dat from A1:F200. If I try to
incorporate the
Range(Range("a1"), Range("a1").End(xlToRight).End(xlDown)) method, it
doesn't work.

Any help (quickly!) would be greatly appreciated!

Thanx in advance!
Benoit
 
J

JE McGimpsey

benoize said:
I'm writing a macro in which I need to print out a variable range. One
day it could be from A1:F10, the other dat from A1:F200. If I try to
incorporate the
Range(Range("a1"), Range("a1").End(xlToRight).End(xlDown)) method, it
doesn't work.

Any help (quickly!) would be greatly appreciated!

It's hard to tell how to answer when you say "it doesn't work", since
that could mean so many things. Do you get an error? Do you get the
wrong range? Do you get a crash?

How is your data laid out? What actually happens? What do you want to
happen?

What version of XL are you using?

Please paste the relevant portion of the code in your reply. I'm sure
"the Range(Range("a1"), Range("a1").End(xlToRight).End(xlDown)) method"
is crystal clear to you, but I can think of several possible ways to
implement that in a procedure, which would lead to different solutions...

Just as a flyer, if you want to print out from A1 to the last filled row
in column F you could use:

With ActiveSheet
.PageSetup.PrintArea = .Range("A1:F" & _
.Range("F" & .Rows.Count).End(xlUp).Row).Address(False, False)
End With
 
B

benoize

Thanks for the help. It worked very well. Sorry I wasn't a bit more
clear in my statement of the problem but you seemed to have gotten the
idea very well. Once again, thanks!

In answer to one of your many questions (the others are academic now)
I'm using XL 2004, which I think is a vast improvement to the verison
before that. That crashed continously. This one seems to be very
stable.

regards, Benoit
 
J

JE McGimpsey

benoize said:
Thanks for the help. It worked very well. Sorry I wasn't a bit more
clear in my statement of the problem but you seemed to have gotten the
idea very well. Once again, thanks!

Well, unfortunately I made it lots more complicated than it need be,
then...

Try:

With ActiveSheet
.PageSetup.PrintArea = "A1:F" & _
.Range("F" & .Rows.Count).End(xlUp).Row
End With
 

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