Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing Question.

Status
Not open for further replies.

bnageshrao

Programmer
Mar 17, 2001
83
US
I have a spread sheet which has about 999 rows. User keeps typing in the data in the columns. At any time if they want to take a print out of the spread sheet the logic is as follows.
We have to find out the last row in which they have entered the value in the first column and then print from 1st row until that row in which they have data in the first column of whatever row it may be. Suppose if they have first column in 26th row then the Print area will be ActiveSheet.PageSetup.PrintArea = "$A$1:$L$26" or ActiveSheet.PageSetup.PrintArea = "$A$1:$L$47" if they have data in the 1st column of 47th row. I can write a loop to find which is the last row has value in first column. Once I find out how do you pass on that variable row number as the number for the last column in that row. For eg if there is a data in 26th row I should be able to say it is $L$26, or if there is a data in 47th row I should be able to say it is $L$47, and so on. $A$1 is always the starting column but the other column varies depending on the value in the first column of the row. When I got the row number I triede to concat that with L but had some problems. Any help is appreciated.

 
I thought if i write the code it will be easy to understand and this is what i wrotePrivate Sub cmdPrint_Click()
Dim strcolumn
For i = 1009 To 11 Step -1
If Worksheets(&quot;CRdata&quot;).Cells(i, 1).Value <> &quot;&quot; Then
strcolumn = i
Exit For
End If
Next
strlcolumn = &quot;$&quot; + &quot;L&quot; + &quot;$&quot; + CStr(strcolumn)
ActiveSheet.PageSetup.PrintArea = &quot;$A$1: strlcolumn&quot;
With ActiveSheet.PageSetup
.LeftHeader = &quot;&quot;
.CenterHeader = &quot;&quot;
.RightHeader = &quot;&quot;
.LeftFooter = &quot;&quot;
.CenterFooter = &quot;&quot;
.RightFooter = &quot;&quot;
.LeftMargin = Application.InchesToPoints(0.75)
.RightMargin = Application.InchesToPoints(0.75)
.TopMargin = Application.InchesToPoints(1)
.BottomMargin = Application.InchesToPoints(1)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
End With
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End Sub

When I run this code the following error comes
Runtime error '1004'
Unable to set the print area property of the page setup class
 
I figured it out finally, all I did was changing the code to
ActiveSheet.PageSetup.PrintArea = &quot;$A$1:&quot; & strlcolumn

Sorry for the unnecessary trouble
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top