Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Print Range Question

I am trying to develp a macro that will set the Print Range in a worksheet. I
have tried to modify several macos on the forums with no success. The problem
is I need to count down to the bottom of column A (which does contain some
blanks), to the first row that contains 0. Then I want the macro to set the
Print Range to A1:FX, where X is equal to the last row before the 0.

Thanks in advance! (Using Excel 2003)


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Print Range Question

Try this macro...

Sub SetPrintArea()
Dim C As Range
With Worksheets(2)
Set C = .Range("A:A").Find(What:=0, LookIn:=xlValues, LookAt:=xlWhole)
If Not C Is Nothing Then
.PageSetup.PrintArea = "$A$1:$F$" & C.Offset(-1).Row
End If
End With
End Sub

Rick


"John" wrote in message
...
I am trying to develp a macro that will set the Print Range in a worksheet.
I
have tried to modify several macos on the forums with no success. The
problem
is I need to count down to the bottom of column A (which does contain some
blanks), to the first row that contains 0. Then I want the macro to set
the
Print Range to A1:FX, where X is equal to the last row before the 0.

Thanks in advance! (Using Excel 2003)



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Print Range Question

Nope...this is still setting the print area to far. It's including all the
rows in column A that contain 0.

"Rick Rothstein (MVP - VB)" wrote:

Try this macro...

Sub SetPrintArea()
Dim C As Range
With Worksheets(2)
Set C = .Range("A:A").Find(What:=0, LookIn:=xlValues, LookAt:=xlWhole)
If Not C Is Nothing Then
.PageSetup.PrintArea = "$A$1:$F$" & C.Offset(-1).Row
End If
End With
End Sub

Rick


"John" wrote in message
...
I am trying to develp a macro that will set the Print Range in a worksheet.
I
have tried to modify several macos on the forums with no success. The
problem
is I need to count down to the bottom of column A (which does contain some
blanks), to the first row that contains 0. Then I want the macro to set
the
Print Range to A1:FX, where X is equal to the last row before the 0.

Thanks in advance! (Using Excel 2003)




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Print Range Question

I don't see how it could possibly be doing that. Are you using the code
exactly as I posted it? All my tests show the code finding the first zero in
Column A (whether a number or text; whether typed in or the result of a
formula) and then setting the print area from A1 to the row in Colum F
immediately before it. Did you change my test Worksheets reference to the
worksheet where your data actually is?

Rick


"John" wrote in message
...
Nope...this is still setting the print area to far. It's including all the
rows in column A that contain 0.

"Rick Rothstein (MVP - VB)" wrote:

Try this macro...

Sub SetPrintArea()
Dim C As Range
With Worksheets(2)
Set C = .Range("A:A").Find(What:=0, LookIn:=xlValues,
LookAt:=xlWhole)
If Not C Is Nothing Then
.PageSetup.PrintArea = "$A$1:$F$" & C.Offset(-1).Row
End If
End With
End Sub

Rick


"John" wrote in message
...
I am trying to develp a macro that will set the Print Range in a
worksheet.
I
have tried to modify several macos on the forums with no success. The
problem
is I need to count down to the bottom of column A (which does contain
some
blanks), to the first row that contains 0. Then I want the macro to set
the
Print Range to A1:FX, where X is equal to the last row before the 0.

Thanks in advance! (Using Excel 2003)





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 209
Default Print Range Question

'/========================================/
Sub Macro1()
Dim i As Long, lngLastRow As Long

Range("A1").Select

lngLastRow = _
ActiveSheet.UsedRange.Columns(1). _
SpecialCells(xlCellTypeLastCell).Row

For i = 1 To lngLastRow - 1
If ActiveCell.Offset(i, 0).Value2 = 0 And _
Not IsEmpty(ActiveCell.Offset(i, 0).Value2) Then
lngLastRow = ActiveCell.Offset(i, 0).Row - 1
Exit For
End If
Next i

ActiveSheet.PageSetup.PrintArea = "$A$1:$F$" & lngLastRow

End Sub
'/========================================/

--
Hope this helps.
Thanks in advance for your feedback.
Gary Brown


"John" wrote:

I am trying to develp a macro that will set the Print Range in a worksheet. I
have tried to modify several macos on the forums with no success. The problem
is I need to count down to the bottom of column A (which does contain some
blanks), to the first row that contains 0. Then I want the macro to set the
Print Range to A1:FX, where X is equal to the last row before the 0.

Thanks in advance! (Using Excel 2003)




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Print Range Question

Rick

Yep, I changed the code to point to the sheet that I wanted it to set the
Print Range and no go. : (

"Rick Rothstein (MVP - VB)" wrote:

I don't see how it could possibly be doing that. Are you using the code
exactly as I posted it? All my tests show the code finding the first zero in
Column A (whether a number or text; whether typed in or the result of a
formula) and then setting the print area from A1 to the row in Colum F
immediately before it. Did you change my test Worksheets reference to the
worksheet where your data actually is?

Rick


"John" wrote in message
...
Nope...this is still setting the print area to far. It's including all the
rows in column A that contain 0.

"Rick Rothstein (MVP - VB)" wrote:

Try this macro...

Sub SetPrintArea()
Dim C As Range
With Worksheets(2)
Set C = .Range("A:A").Find(What:=0, LookIn:=xlValues,
LookAt:=xlWhole)
If Not C Is Nothing Then
.PageSetup.PrintArea = "$A$1:$F$" & C.Offset(-1).Row
End If
End With
End Sub

Rick


"John" wrote in message
...
I am trying to develp a macro that will set the Print Range in a
worksheet.
I
have tried to modify several macos on the forums with no success. The
problem
is I need to count down to the bottom of column A (which does contain
some
blanks), to the first row that contains 0. Then I want the macro to set
the
Print Range to A1:FX, where X is equal to the last row before the 0.

Thanks in advance! (Using Excel 2003)






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Print Range Question

This works perfectly, thanks!

"Gary Brown" wrote:

'/========================================/
Sub Macro1()
Dim i As Long, lngLastRow As Long

Range("A1").Select

lngLastRow = _
ActiveSheet.UsedRange.Columns(1). _
SpecialCells(xlCellTypeLastCell).Row

For i = 1 To lngLastRow - 1
If ActiveCell.Offset(i, 0).Value2 = 0 And _
Not IsEmpty(ActiveCell.Offset(i, 0).Value2) Then
lngLastRow = ActiveCell.Offset(i, 0).Row - 1
Exit For
End If
Next i

ActiveSheet.PageSetup.PrintArea = "$A$1:$F$" & lngLastRow

End Sub
'/========================================/

--
Hope this helps.
Thanks in advance for your feedback.
Gary Brown


"John" wrote:

I am trying to develp a macro that will set the Print Range in a worksheet. I
have tried to modify several macos on the forums with no success. The problem
is I need to count down to the bottom of column A (which does contain some
blanks), to the first row that contains 0. Then I want the macro to set the
Print Range to A1:FX, where X is equal to the last row before the 0.

Thanks in advance! (Using Excel 2003)


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Print Range Question

Can you post your worksheet on line somewhere for us to download and look
at? While you will get the best possible answer if more than my eyes look at
it; but, if you want, you can send the worksheet directly to me (remove the
two NO.SPAM text entries from my address) and I will see if I can find out
why you are getting different results than I am with my code.

Rick


"John" wrote in message
...
Rick

Yep, I changed the code to point to the sheet that I wanted it to set the
Print Range and no go. : (

"Rick Rothstein (MVP - VB)" wrote:

I don't see how it could possibly be doing that. Are you using the code
exactly as I posted it? All my tests show the code finding the first zero
in
Column A (whether a number or text; whether typed in or the result of a
formula) and then setting the print area from A1 to the row in Colum F
immediately before it. Did you change my test Worksheets reference to the
worksheet where your data actually is?

Rick


"John" wrote in message
...
Nope...this is still setting the print area to far. It's including all
the
rows in column A that contain 0.

"Rick Rothstein (MVP - VB)" wrote:

Try this macro...

Sub SetPrintArea()
Dim C As Range
With Worksheets(2)
Set C = .Range("A:A").Find(What:=0, LookIn:=xlValues,
LookAt:=xlWhole)
If Not C Is Nothing Then
.PageSetup.PrintArea = "$A$1:$F$" & C.Offset(-1).Row
End If
End With
End Sub

Rick


"John" wrote in message
...
I am trying to develp a macro that will set the Print Range in a
worksheet.
I
have tried to modify several macos on the forums with no success.
The
problem
is I need to count down to the bottom of column A (which does
contain
some
blanks), to the first row that contains 0. Then I want the macro to
set
the
Print Range to A1:FX, where X is equal to the last row before the 0.

Thanks in advance! (Using Excel 2003)







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
Print Blank Pgs - Preview margins outside print range dsm Excel Discussion (Misc queries) 0 October 25th 06 06:17 PM
Can you get the range reference for each page in a worksheet print range? Crosby Excel Programming 3 April 12th 05 06:06 PM
Range Question / error 1004: method Range of object Worksheet has failed Paul Excel Programming 3 April 7th 05 02:56 PM
Excel 2000 VBA - Set Print Range in dynamic range sub_pop[_5_] Excel Programming 2 July 27th 04 08:01 PM
Range.Formula and Range question using Excel Automation [email protected] Excel Programming 0 September 19th 03 04:53 AM


All times are GMT +1. The time now is 08:06 AM.

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

About Us

"It's about Microsoft Excel"