Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Member
 
Posts: 33
Default Printing spreadsheets macro

Hi All,

I currently print forms which i want a macro for. However the table size in the form varies. Sometimes it is 3 coulmns and 2 rows, sometimes 7 coluimns and 20 rows (which goes over 2 pages).

Is there a way the macro button can say ' if 7 columns & 15 rows' print on 2 pages wide.
If '<3 columns' print on 1 page.

Any help here would be great.

Toms
  #2   Report Post  
Posted to microsoft.public.excel.misc
Kevin B
 
Posts: n/a
Default Printing spreadsheets macro

The following macros assumes that the area to print consists of contiguous
rows and columns.

Substitute the starting range and the sheet name to match your starting cell
and sheet name and this should work for you.

Sub PrintPages()

Dim wb As Workbook
Dim ws As Worksheet
Dim r As Range
Dim iRows As Integer
Dim iCols As Integer

Set wb = ActiveWorkbook
Set ws = wb.Sheets("Sheet1")

'Activate sheet 1 and select cell A1
ws.Activate
Range("A1").Select

'Select the current region and assign the
'range name PrintRange to the selection
Selection.CurrentRegion.Select
Selection.Name = "PrintRange"
Set r = Range("PrintRange")

'Get the number of rows and columns in the
'current PrintRange
iRows = r.Rows.Count
iCols = r.Columns.Count

'Set print parameters based upon row & column
'counts
If iCols 7 And iRows 15 Then
With ActiveSheet.PageSetup
.FitToPagesWide = 2
.FitToPagesTall = 1
End With
Else
With ActiveSheet.PageSetup
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
End If

Set wb = Nothing
Set ws = Nothing
Set r = Nothing

End Sub

--
Kevin Backmann


"GarToms" wrote:


Hi All,

I currently print forms which i want a macro for. However the table
size in the form varies. Sometimes it is 3 coulmns and 2 rows,
sometimes 7 coluimns and 20 rows (which goes over 2 pages).

Is there a way the macro button can say ' if 7 columns & 15 rows'
print on 2 pages wide.
If '<3 columns' print on 1 page.

Any help here would be great.

Toms


--
GarToms

  #3   Report Post  
Member
 
Posts: 33
Default

That is excellent. Thanks a lot. However I am unable to get it to work as it gets stuck on the if statement.
Also the 'current region' function for the print range does not include 6 of the end columns (unsure as to why, think it may be due to them not having formulas in). Is there a function that can drag the selection across 6 columns each time?

Thanks for the help so far.

Quote:
Originally Posted by Kevin B
The following macros assumes that the area to print consists of contiguous
rows and columns.

Substitute the starting range and the sheet name to match your starting cell
and sheet name and this should work for you.

Sub PrintPages()

Dim wb As Workbook
Dim ws As Worksheet
Dim r As Range
Dim iRows As Integer
Dim iCols As Integer

Set wb = ActiveWorkbook
Set ws = wb.Sheets("Sheet1")

'Activate sheet 1 and select cell A1
ws.Activate
Range("A1").Select

'Select the current region and assign the
'range name PrintRange to the selection
Selection.CurrentRegion.Select
Selection.Name = "PrintRange"
Set r = Range("PrintRange")

'Get the number of rows and columns in the
'current PrintRange
iRows = r.Rows.Count
iCols = r.Columns.Count

'Set print parameters based upon row & column
'counts
If iCols 7 And iRows 15 Then 'gets stuck here
With ActiveSheet.PageSetup
.FitToPagesWide = 2
.FitToPagesTall = 1
End With
Else
With ActiveSheet.PageSetup
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
End If

Set wb = Nothing
Set ws = Nothing
Set r = Nothing

End Sub

--
Kevin Backmann


"GarToms" wrote:


Hi All,

I currently print forms which i want a macro for. However the table
size in the form varies. Sometimes it is 3 coulmns and 2 rows,
sometimes 7 coluimns and 20 rows (which goes over 2 pages).

Is there a way the macro button can say ' if 7 columns & 15 rows'
print on 2 pages wide.
If '3 columns' print on 1 page.

Any help here would be great.

Toms


--
GarToms
  #4   Report Post  
Member
 
Posts: 33
Default

i have resolved the issue of not picking up all the cells now however i get an error 400 when i run the code. Does anyone know how i can resolve this?

Quote:
Originally Posted by GarToms
That is excellent. Thanks a lot. However I am unable to get it to work as it gets stuck on the if statement.
Also the 'current region' function for the print range does not include 6 of the end columns (unsure as to why, think it may be due to them not having formulas in). Is there a function that can drag the selection across 6 columns each time?

Thanks for the help so far.
  #5   Report Post  
Posted to microsoft.public.excel.misc
Kevin B
 
Posts: n/a
Default Printing spreadsheets macro

If this is still an issued, post your code here so it can be reviewed.
--
Kevin Backmann


"GarToms" wrote:


i have resolved the issue of not picking up all the cells now however i
get an error 400 when i run the code. Does anyone know how i can
resolve this?

GarToms Wrote:
That is excellent. Thanks a lot. However I am unable to get it to work
as it gets stuck on the if statement.
Also the 'current region' function for the print range does not include
6 of the end columns (unsure as to why, think it may be due to them not
having formulas in). Is there a function that can drag the selection
across 6 columns each time?

Thanks for the help so far.



--
GarToms



  #6   Report Post  
Member
 
Posts: 33
Default

I'v worked it out now. Thanks for your help Kevin.


Quote:
Originally Posted by Kevin B
If this is still an issued, post your code here so it can be reviewed.
--
Kevin Backmann


"GarToms" wrote:


i have resolved the issue of not picking up all the cells now however i
get an error 400 when i run the code. Does anyone know how i can
resolve this?

GarToms Wrote:
That is excellent. Thanks a lot. However I am unable to get it to work
as it gets stuck on the if statement.
Also the 'current region' function for the print range does not include
6 of the end columns (unsure as to why, think it may be due to them not
having formulas in). Is there a function that can drag the selection
across 6 columns each time?

Thanks for the help so far.



--
GarToms
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can T Get Macro To Run! Nipper New Users to Excel 2 November 4th 05 04:48 AM
Need assistance with printing macro Greegan Excel Worksheet Functions 0 September 7th 05 05:29 PM
macro with F9 Kenny Excel Discussion (Misc queries) 1 August 3rd 05 02:41 PM
Make Alignment options under format cells available as shortcut dforrest Excel Discussion (Misc queries) 1 July 14th 05 10:58 PM
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM


All times are GMT +1. The time now is 03:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"