Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 85
Default setting print range

I know how to set a print range w/ the columns set and the rows varying, but
what about the other way around where I don't know the number of columns
every time?

this works for varying rows:
varyingrows = 8
Sheets("testpage").PageSetup.PrintArea = "a1:j" & varyingrows

I tried this for varying columns with no luck:
varyingcolumns=10 'will change w/ every run
Sheets("testpage").PageSetup.PrintArea =
range(cells(1,1),cells(8,varyingcolumns)

any thoughts? thanks, mike allen


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default setting print range

Hi Mike

you could try something like this to find the last used row and column
then use that info to set your print range.

Option Explicit
Dim VaryingRows As Integer
Dim VaryingColumns As String
Dim MyLen As Long

Private Sub CommandButton1_Click()
VaryingRows = [a1].End(xlDown).Row 'Find last used row in Column A
VaryingColumns = [a1].End(xlToRight).Address 'Find last used column in
Row 1
MyLen = Len(VaryingColumns) 'Check if column is single letter or
double
If MyLen = 5 Then
VaryingColumns = Mid(VaryingColumns, 2, 2) 'Take the column letter
from the string
Else
VaryingColumns = Mid(VaryingColumns, 2, 1)
End If
'Set your print area
Sheets("testpage").PageSetup.PrintArea = "a1:" & VaryingColumns &
VaryingRows
End Sub

Hope this is of some help to you

S

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default setting print range

Hi Mike

Sorry if this post appears twice i sent it through already but it
hasn't appeared.

You could try something like the code below that finds the last used
column and row referencing from the cell A1 then sets the print area
using this info.

Option Explicit
Dim VaryingRows As Integer
Dim VaryingColumns As String
Dim MyLen As Long

Private Sub CommandButton1_Click()
VaryingRows = [A1].End(xlDown).Row 'Find last used row in Column A
VaryingColumns = [A1].End(xlToRight).Address 'Find last used column in
Row 1
MyLen = Len(VaryingColumns) 'Check if column is single letter or
double
If MyLen = 5 Then
VaryingColumns = Mid(VaryingColumns, 2, 2) 'Take the column letter
from the string
Else
VaryingColumns = Mid(VaryingColumns, 2, 1)
End If
'Set your print area
Sheets("Sheet1").PageSetup.PrintArea = "A1:" & VaryingColumns &
VaryingRows
End Sub

I hope this is of some help to you.

S

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 85
Default setting print range

i got it! it works just fine. the main thing i left out was the ...Address
suffix. thank you, mike allen
"Incidental" wrote in message
oups.com...
Hi Mike

Sorry if this post appears twice i sent it through already but it
hasn't appeared.

You could try something like the code below that finds the last used
column and row referencing from the cell A1 then sets the print area
using this info.

Option Explicit
Dim VaryingRows As Integer
Dim VaryingColumns As String
Dim MyLen As Long

Private Sub CommandButton1_Click()
VaryingRows = [A1].End(xlDown).Row 'Find last used row in Column A
VaryingColumns = [A1].End(xlToRight).Address 'Find last used column in
Row 1
MyLen = Len(VaryingColumns) 'Check if column is single letter or
double
If MyLen = 5 Then
VaryingColumns = Mid(VaryingColumns, 2, 2) 'Take the column letter
from the string
Else
VaryingColumns = Mid(VaryingColumns, 2, 1)
End If
'Set your print area
Sheets("Sheet1").PageSetup.PrintArea = "A1:" & VaryingColumns &
VaryingRows
End Sub

I hope this is of some help to you.

S



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
Setting print range with macro Deeds Excel Programming 4 October 4th 05 04:22 PM
Setting print range using VBA Dave Ramage[_2_] Excel Programming 0 July 29th 03 04:35 PM
Setting print range using VBA VBANut Excel Programming 0 July 29th 03 04:20 PM
Setting print range using VBA Ron de Bruin Excel Programming 0 July 29th 03 03:59 PM
Setting Print range Tom Ogilvy Excel Programming 3 July 25th 03 04:06 AM


All times are GMT +1. The time now is 01:41 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"