Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default using formuals

I have a repeating IF statement running down column A for 200 rows. I'm
making an assumption that I will not need more than 200 rows ever but I have
no idea how many rows I may need. My issue is thta because of the 200 rows
being used by the formula when I print the worksheet it prints all 200 rows
now just the rows that have real data. If there a way besides having the user
set the print area to only print rows with real data??
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default using formuals

Assuming you can base the print area selection on another column (e.g. sure
column A has 200 values but column B will always - and only - have a value
for each row we want to print), then you can set up a "Set_My_Print_Area"
macro like this:

Sub Set_My_Print_Area()

Dim StartCell As String
StartCell = "A1" 'Whatever the upper left corner of the page range will be.
Range("B1").Select 'the column I mentioned earlier that we can use as our
test.
'Find the last row
Selection.End(xlDown).Select

'Now set the print area. Change the "G" to whatever the last column is you
want to print.
ActiveSheet.PageSetup.PrintArea = StartCell & ":" & "G" & ActiveCell.Row

End Sub

"hshayhorn" wrote:

I have a repeating IF statement running down column A for 200 rows. I'm
making an assumption that I will not need more than 200 rows ever but I have
no idea how many rows I may need. My issue is thta because of the 200 rows
being used by the formula when I print the worksheet it prints all 200 rows
now just the rows that have real data. If there a way besides having the user
set the print area to only print rows with real data??

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default using formuals

This will set your print area for the visible values of column A only. If
you want more columns to print, it will require modification. It will adjust
according to only the cells that show values.

Sub prtArea()
Dim lr As Long, bRng As String
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For i = lr To 1 Step -1
If Cells(i, 1) < "" Then
bRng = Cells(i, 1).Address
Exit For
End If
Next
ActiveSheet.PageSetup.PrintArea = "A1:" & bRng
End Sub




"hshayhorn" wrote:

I have a repeating IF statement running down column A for 200 rows. I'm
making an assumption that I will not need more than 200 rows ever but I have
no idea how many rows I may need. My issue is thta because of the 200 rows
being used by the formula when I print the worksheet it prints all 200 rows
now just the rows that have real data. If there a way besides having the user
set the print area to only print rows with real data??

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default using formuals

Where do I paste the code? I pasted it on the worksheet but it doesn't seem
to work. I still get more pages than I think I should. If I do a control down
arrow on column A there is only 70 rows of data but I still get 12 pages when
I print.

"JLGWhiz" wrote:

This will set your print area for the visible values of column A only. If
you want more columns to print, it will require modification. It will adjust
according to only the cells that show values.

Sub prtArea()
Dim lr As Long, bRng As String
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For i = lr To 1 Step -1
If Cells(i, 1) < "" Then
bRng = Cells(i, 1).Address
Exit For
End If
Next
ActiveSheet.PageSetup.PrintArea = "A1:" & bRng
End Sub




"hshayhorn" wrote:

I have a repeating IF statement running down column A for 200 rows. I'm
making an assumption that I will not need more than 200 rows ever but I have
no idea how many rows I may need. My issue is thta because of the 200 rows
being used by the formula when I print the worksheet it prints all 200 rows
now just the rows that have real data. If there a way besides having the user
set the print area to only print rows with real data??

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default using formuals

The code goes in the standard module1 in the VB editor. If you want it to
print immediately after setting the print area then use this modified code
below.

You can tell if the code is effective by the dotted line that outlines the
print area.
Note that it uses ActiveSheet as the Worksheet object. Be sure that the
sheet you want to print from is the active sheet when you run the code.

Sub prtArea()
Dim lr As Long, bRng As String
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For i = lr To 1 Step -1
If Cells(i, 1) < "" Then
bRng = Cells(i, 1).Address
Exit For
End If
Next
ActiveSheet.PageSetup.PrintArea = "A1:" & bRng
ActiveSheet.PrintOut
End Sub

To avoid printing unnecessary pages while testing this, use the
FilePageSetUpOptionsMain and in the lower right area of the dialog box,
check the Print Preview. That will allow you to see what is about to be
printed before it actually prints and if you do not want to continue the
action, you can cancel without printing anything. Then when you are
satisfied with the procedure, you can go back and uncheck the print preview.








"hshayhorn" wrote:

Where do I paste the code? I pasted it on the worksheet but it doesn't seem
to work. I still get more pages than I think I should. If I do a control down
arrow on column A there is only 70 rows of data but I still get 12 pages when
I print.

"JLGWhiz" wrote:

This will set your print area for the visible values of column A only. If
you want more columns to print, it will require modification. It will adjust
according to only the cells that show values.

Sub prtArea()
Dim lr As Long, bRng As String
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For i = lr To 1 Step -1
If Cells(i, 1) < "" Then
bRng = Cells(i, 1).Address
Exit For
End If
Next
ActiveSheet.PageSetup.PrintArea = "A1:" & bRng
End Sub




"hshayhorn" wrote:

I have a repeating IF statement running down column A for 200 rows. I'm
making an assumption that I will not need more than 200 rows ever but I have
no idea how many rows I may need. My issue is thta because of the 200 rows
being used by the formula when I print the worksheet it prints all 200 rows
now just the rows that have real data. If there a way besides having the user
set the print area to only print rows with real data??



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default using formuals

P.S. You have to run the code for it to work. In Excel, from the menu bar,
Click ToolsMacroMacros then click the name of the macro to run, when it
appears in the small window at the top of the dialog box, click Run.

"hshayhorn" wrote:

Where do I paste the code? I pasted it on the worksheet but it doesn't seem
to work. I still get more pages than I think I should. If I do a control down
arrow on column A there is only 70 rows of data but I still get 12 pages when
I print.

"JLGWhiz" wrote:

This will set your print area for the visible values of column A only. If
you want more columns to print, it will require modification. It will adjust
according to only the cells that show values.

Sub prtArea()
Dim lr As Long, bRng As String
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For i = lr To 1 Step -1
If Cells(i, 1) < "" Then
bRng = Cells(i, 1).Address
Exit For
End If
Next
ActiveSheet.PageSetup.PrintArea = "A1:" & bRng
End Sub




"hshayhorn" wrote:

I have a repeating IF statement running down column A for 200 rows. I'm
making an assumption that I will not need more than 200 rows ever but I have
no idea how many rows I may need. My issue is thta because of the 200 rows
being used by the formula when I print the worksheet it prints all 200 rows
now just the rows that have real data. If there a way besides having the user
set the print area to only print rows with real data??

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default using formuals

Out of curiosity, have you tried manually setting the print area by selecting
the area you want to print and then FilePrintAreaSet Print Area ?

"hshayhorn" wrote:

Where do I paste the code? I pasted it on the worksheet but it doesn't seem
to work. I still get more pages than I think I should. If I do a control down
arrow on column A there is only 70 rows of data but I still get 12 pages when
I print.

"JLGWhiz" wrote:

This will set your print area for the visible values of column A only. If
you want more columns to print, it will require modification. It will adjust
according to only the cells that show values.

Sub prtArea()
Dim lr As Long, bRng As String
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For i = lr To 1 Step -1
If Cells(i, 1) < "" Then
bRng = Cells(i, 1).Address
Exit For
End If
Next
ActiveSheet.PageSetup.PrintArea = "A1:" & bRng
End Sub




"hshayhorn" wrote:

I have a repeating IF statement running down column A for 200 rows. I'm
making an assumption that I will not need more than 200 rows ever but I have
no idea how many rows I may need. My issue is thta because of the 200 rows
being used by the formula when I print the worksheet it prints all 200 rows
now just the rows that have real data. If there a way besides having the user
set the print area to only print rows with real data??

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default using formuals

That actually works great except that there is more an 1 column in the
worksheet that needs to be printed. I need all the columns in that row.
Column P is my last column on that sheet.

"JLGWhiz" wrote:

This will set your print area for the visible values of column A only. If
you want more columns to print, it will require modification. It will adjust
according to only the cells that show values.

Sub prtArea()
Dim lr As Long, bRng As String
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For i = lr To 1 Step -1
If Cells(i, 1) < "" Then
bRng = Cells(i, 1).Address
Exit For
End If
Next
ActiveSheet.PageSetup.PrintArea = "A1:" & bRng
End Sub




"hshayhorn" wrote:

I have a repeating IF statement running down column A for 200 rows. I'm
making an assumption that I will not need more than 200 rows ever but I have
no idea how many rows I may need. My issue is thta because of the 200 rows
being used by the formula when I print the worksheet it prints all 200 rows
now just the rows that have real data. If there a way besides having the user
set the print area to only print rows with real data??

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
Formuals Gene McKinney YMCA international Excel Discussion (Misc queries) 2 April 30th 08 08:09 PM
New to Formuals Tanya Excel Worksheet Functions 2 May 12th 07 04:30 AM
Coding if formuals jln via OfficeKB.com Excel Programming 4 December 18th 06 04:09 PM
Need to place 3 formuals in VBA jln via OfficeKB.com Excel Programming 1 November 8th 06 03:58 PM
IF, Then formuals Cheryle Excel Programming 1 July 1st 04 07:27 AM


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