Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / December 2007

Tip: Looking for answers? Try searching our database.

Set Page Break Lines using VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sam Kuo - 26 Nov 2007 23:44 GMT
I'd like to set page break lines and print area in a worksheet using VBA, but
have no idea how to do this...

I have a worksheet with 11 pages (of the same size) when viewed in Page
Break Preview:
- Page 1 has a content table with 10 cells (B1:B10) where user can enter the
report titles.
- Page 2 shows contents under Title #1 (title name is entered in cell B1);
Page 3 for Title #2; and so on.

I'm hoping to only show and print Page 1, plus any other pages only if their
titles have been entered in the content table. (e.g. if only 3 titles are
entered, just show page 1 and the other 3 pages).

Any help would be appreciated (preferably with example and
explanation..because I'm just helpless with programming)
Aran Black - 27 Nov 2007 17:16 GMT
Sam,

I have written the following routine for you as per your specifications.
You need to insert page breaks at the end of each of your ranges first.
Let me know if you have any questions!
Aran
(Please rate this response)

Private Sub CommandButton1_Click()

var1 = Null
var2 = Null
var3 = Null
var4 = Null
var5 = Null
var6 = Null
var7 = Null
var8 = Null
var9 = Null
var10 = Null

If IsEmpty(Sheet1.Range("b1")) = True Then
Else
var1 = "$A$11:$f$20" & Chr(44)
End If

If IsEmpty(Sheet1.Range("b2")) = True Then
Else
var2 = "$A$21:$f$30" & Chr(44)
End If

If IsEmpty(Sheet1.Range("b3")) = True Then
Else
var3 = "$A$31:$f$40" & Chr(44)
End If

If IsEmpty(Sheet1.Range("b4")) = True Then
Else
var4 = "$A$41:$f$50" & Chr(44)
End If

If IsEmpty(Sheet1.Range("b5")) = True Then
Else
var5 = "$A$51:$f$60" & Chr(44)
End If

If IsEmpty(Sheet1.Range("b6")) = True Then
Else
var6 = "$A$61:$f$70" & Chr(44)
End If

If IsEmpty(Sheet1.Range("b7")) = True Then
Else
var7 = "$A$71:$f$80" & Chr(44)
End If

If IsEmpty(Sheet1.Range("b8")) = True Then
Else

var8 = "$A$81:$f$90" & Chr(44)
End If
If IsEmpty(Sheet1.Range("b9")) = True Then
Else
var9 = "$A$91:$f$100" & Chr(44)
End If

If IsEmpty(Sheet1.Range("b10")) = True Then
Else
var10 = "$A$101:$f$110"
End If

var11 = var1 & var2 & var3 & var4 & var5 & var6 & var7 & var8 & var9 & var10

ActiveSheet.PageSetup.PrintArea = var11

End Sub

Signature

It wasnt Jesus it was just a fella!
God Bless America!

> I'd like to set page break lines and print area in a worksheet using VBA, but
> have no idea how to do this...
[quoted text clipped - 12 lines]
> Any help would be appreciated (preferably with example and
> explanation..because I'm just helpless with programming)
Sam Kuo - 21 Dec 2007 02:16 GMT
Thank you Aran. Its great.

> Sam,
>
[quoted text clipped - 89 lines]
> > Any help would be appreciated (preferably with example and
> > explanation..because I'm just helpless with programming)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.