MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old May 2nd, 2002, 04:22 AM   #1
Andy D 2002
Board Regular
 
Join Date: Apr 2002
Location: Andy Devine
Posts: 106
Default

Hi
in Column A i've company names e.g

A4 = header
A5:A8 = "Company A"
A9:A10 = "Company B"
A11:A22= "Company C"

Is there a macro that i can use that inserts a page break where the name changes in column A?..
thanks
A
__________________
Andy Devine
Andy D 2002 is offline   Reply With Quote
Old May 2nd, 2002, 04:54 AM   #2
Robb__
New Member
 
Join Date: Apr 2002
Posts: 41
Default

Andy

Try this:

Sub insertBreaks()
Dim c As Range
With Worksheets("Sheet1")
For Each c In .Columns(1).Cells
If c.Address = "$A$1" Then GoTo Skip 'Skip Row 1
If c <> c.Offset(-1, 0) Then 'If the cell above is not the same
.Rows(c.Row).PageBreak = xlPageBreakManual 'Insert a manual pagebreak
Else
End If
Skip:
Next c
End With
End Sub

I don't know how far down the cells are filled. You may like to amend the Column to something shorter.

Any help?

Regards

Robb__
Robb__ is offline   Reply With Quote
Old May 2nd, 2002, 05:27 AM   #3
Andy D 2002
Board Regular
 
Join Date: Apr 2002
Location: Andy Devine
Posts: 106
Default

hi
thanks very much for that...
this creates a break before and after my heading which is in A4 - do you know what i need to do?

Also a new question..where i'm going with this is to get users to print "print report" button & then macro creates 1 client report for each client (where column headings are in row 4)..question..if page 1 shows client 1 and page 2 shows client 2 etc, etc is there a easy way to show client name in say cell B1 (which would be Client 1 on Page 1, client 2 on page 2 etc..)
Hope makes sense ..(?)
Andy
__________________
Andy Devine
Andy D 2002 is offline   Reply With Quote
Old May 2nd, 2002, 05:56 AM   #4
Robb__
New Member
 
Join Date: Apr 2002
Posts: 41
Default

Andy

In answer to the first part:

Replace: If c.Address = "$A$1" Then GoTo Skip 'Skip Row 1


with: If c.Row < 6 Then GoTo Skip 'Skip Row 1

You may need to adjust the row number to suit your situation.

I'm not sure what you are trying to do with the client names. Where do the names come from? When do you want them put into b2?

Regards

Robb__
Robb__ is offline   Reply With Quote
Old May 2nd, 2002, 07:35 AM   #5
Andy D 2002
Board Regular
 
Join Date: Apr 2002
Location: Andy Devine
Posts: 106
Default

Hi Robb
thanks again for this...your revised insert break works really well

Re: Headings - after running the macro page 1 shows information for client 1 only, page 2 shows info for client2 only etc..is there a way of getting the active client name into for example, cell B2, which will be a bold heading..?

Andy

__________________
Andy Devine
Andy D 2002 is offline   Reply With Quote
Old May 3rd, 2002, 06:26 AM   #6
Robb__
New Member
 
Join Date: Apr 2002
Posts: 41
Default

Andy

Where is the client name to be found ie where is it before it is to be put into b2?

Regards

Robb__
Robb__ is offline   Reply With Quote
Old May 3rd, 2002, 07:28 AM   #7
Andy D 2002
Board Regular
 
Join Date: Apr 2002
Location: Andy Devine
Posts: 106
Default

hi rob
client names are in col A
thanks
andy

__________________
Andy Devine
Andy D 2002 is offline   Reply With Quote
Old May 3rd, 2002, 08:03 AM   #8
Robb__
New Member
 
Join Date: Apr 2002
Posts: 41
Default

Andy

There may be an easier way, but this should work.

For the first sheet, I have assumed the client name is in A5. If this is incorrect, you will need to adjust.

After that, the code looks for each pagebreak. Since they are set at the change of the client names in Column1, I have assumed the first cell in Col1 after the pagebreak will contain the client name.

It is then a matter of looping through the pagebreaks. As you will see, each page has to be printed separately.

Sub PrintPages()
Dim x As Integer 'Declare a variable to hold break number

With Worksheets("Sheet1")
.[B2] = .[A5] 'Copy the first client to B2
.Worksheets("Sheet1").PrintOut from:=1, To:=1, copies:=1 'Print the first page

x = .HPageBreaks.Count 'Count the number of pagebreaks to establish the number of pages to print

For x = 1 To x 'For the number of pagebreaks
.[B2] = .Range(.HPageBreaks(x).Location.Address) 'Client name will fill columnA, so copy to B2
.Worksheets("Sheet1").PrintOut from:=x + 1, To:=x + 1, copies:=1 'Print the page - number will be PageBreak number plus 1
Next x

End With
End Sub

Unfortunately, I have not had a chance to test this.

Any help?

Regards

Robb__
Robb__ is offline   Reply With Quote
Old May 3rd, 2002, 09:09 AM   #9
Andy D 2002
Board Regular
 
Join Date: Apr 2002
Location: Andy Devine
Posts: 106
Default

this is great Robb, thanks so much for your help
sorry if client names are in column B not column A what do i need to do?
(already changed.[b2] = .[b5] bit)

__________________
Andy Devine
Andy D 2002 is offline   Reply With Quote
Old May 3rd, 2002, 07:59 PM   #10
Robb__
New Member
 
Join Date: Apr 2002
Posts: 41
Default

Andy

Just replace:
.[B2] = .Range(.HPageBreaks(x).Location.Address)

with:

.[B2] = .Range(.HPageBreaks(x).Location.Address).Offset(0, 1)

Regards

Robb__
Robb__ is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 06:53 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes