Macro or code for Selecting the print area.

G

Guest

Guest
Hope I ask this properly.
I have a dummy spreadsheet set up for the quoting Dept. Range for each can be small to all columns and 10000+ rows.

I only want to print a specific range
lets say B1:F1000. Basically I
want to print to the last active cell in F
which contains data .

Is there coding that will examine a range and determine where the data ends, and I can then set the print area I desire?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Here's the code I used to set the print area for what I thought would work. It didn't. IT set the print area for all of A and all og G. I was hoping it would find the last cell in the last row that contained data.
Which in my trial run was G48.

Code:
Application.Goto Reference:="R1C1"
ActiveCell.Range("A:G").Select
ActiveSheet.PageSetup.PrintArea = "$A:$G"
ActiveCell.Select

What did I do wrong?

_________________
This message was edited by Zac on 2002-02-21 08:36
 
Upvote 0
I think Juan was talking about going to file,page setup and seting the print area to A:F, not using a marco. Hope this helps
 
Upvote 0
Sub setprintarea()
Dim myrange As String
myrange = Cells(Rows.Count, 6).End(xlUp).Address
ActiveSheet.PageSetup.PrintArea = "$A$1:" & myrange
End Sub
This looks for the last used cell in the F column and sets the print area accordingly.

Rick
 
Upvote 0
On 2002-02-21 08:24, Zac wrote:
Here's the code I used to set the print area for what I thought would work. It didn't. IT set the print area for all of A and all og G. I was hoping it would find the last cell in the last row that contained data.
Which in my trial run was G48.

Code:
Application.Goto Reference:="R1C1"
ActiveCell.Range("A:G").Select
ActiveSheet.PageSetup.PrintArea = "$A:$G"
ActiveCell.Select

What did I do wrong?

What ? well, actually, you didn't (You selected a whole bunch of things you didn't need to, but.... Actually THAT works ! unless, you have some "invisible" cells, formulas that return a "". If that's the case then you'll print some extra pages.

Try the macro proposed, that should work.
 
Upvote 0

Forum statistics

Threads
1,213,554
Messages
6,114,280
Members
448,562
Latest member
Flashbond

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