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 Mar 21st, 2002, 05:46 AM   #1
Beckwa
New Member
 
Join Date: Mar 2002
Location: Northampton, UK
Posts: 33
Default

Ok the following code I made should change the colour of the booking form i created to black and white and then print two copies of it before changing the colour back. This part works fine. Then it should add parts of the booking form's information to a seperate worksheet, the Booking Database. This works fine the first time but when the second booking is added, it overwrites the first one and doesn't appear underneath it. I have included the code in case it helps at all!! Thanx, BEX
Sub PrintAndAddBooking()
'
' PrintAndAddBooking Macro
' This will print 2 copies of the booking and add it to the database also.
'

'
Application.ScreenUpdating = False
Sheets("Booking Form").Select
ActiveSheet.Unprotect
Sheets("Booking Database").Select
ActiveSheet.Unprotect
Sheets("Booking Form").Select
Cells.Select
Selection.Interior.ColorIndex = 2
Selection.Font.ColorIndex = 0
Range("C5:D7,H5,H6,H9:J9,C9:E9,C11,C12,C13,E15").Select
Range("E15").Activate
Selection.Interior.ColorIndex = 15
Range("E15:F15").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True
Cells.Select
Selection.Interior.ColorIndex = 41
Range("B1:I3").Select
Selection.Font.ColorIndex = 8
Range("A5:B7,F5:G5,F6:G6,F9:G9,A9:B9,A11:B11,A12:B12,A13:B13").Select
Range("A13").Activate
Selection.Font.ColorIndex = 37
Range("C5:D7,H5,H6,H9:J9,C9:E9,C11,C12,C13,E15").Select
Range("E15").Activate
Selection.Interior.ColorIndex = 5
Range("A15:D15").Select
Selection.Font.ColorIndex = 2
Sheets("Booking Database").Select
Range("A5").Select
Selection.CurrentRegion.Select
'Check for empty table
If Range("A6") <> "" Then
Selection.End(xlDown).Select
End If
ActiveCell.Offset(1, 0).Range("A1").Select
Sheets("Booking Form").Select
Range("BookingDate").Select
Selection.Copy
Sheets("Booking Database").Select
ActiveSheet.Paste
ActiveCell.Offset(0, 1).Range("A1").Select
Sheets("Booking Form").Select
Range("BookingNumber").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Booking Database").Select
ActiveSheet.Paste
ActiveCell.Offset(0, 1).Range("A1").Select
Sheets("Booking Form").Select
Range("MilesTravelled").Select
Application.CutCopyMode = False
Selection.Copy
ActiveCell.Offset(0, 1).Range("A1").Select
Sheets("Booking Database").Select
ActiveSheet.Paste
ActiveCell.Offset(0, 1).Range("A1").Select
Sheets("Booking Form").Select
Range("CostForJourney").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Booking Database").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Sheets("Booking Form").Select
Application.CutCopyMode = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets("Booking Database").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Application.ScreenUpdating = True
End Sub


[ This Message was edited by: Beckwa on 2002-03-21 07:12 ]
Beckwa is offline   Reply With Quote
Old Mar 21st, 2002, 06:47 AM   #2
Russell
New Member
 
Join Date: Mar 2002
Posts: 39
Default

Is Cell A5/row 5 blank on the booking database sheet. If so when you select the current region and then use xldown it only takes you A6
Change to Range("A6").select and then select current region

Russell
Russell is offline   Reply With Quote
Old Mar 21st, 2002, 07:25 AM   #3
Beckwa
New Member
 
Join Date: Mar 2002
Location: Northampton, UK
Posts: 33
Default

Thanks for the advice but it still isn't working!! Any more ideas? Thanx Bex

[ This Message was edited by: Beckwa on 2002-03-21 07:11 ]
Beckwa is offline   Reply With Quote
Old Mar 21st, 2002, 08:18 AM   #4
Joe Was
MrExcel MVP
 
Joe Was's Avatar
 
Join Date: Feb 2002
Location: Central Florida, USA
Posts: 7,541
Default

Below is a sample of how this concept works. To copy to a list, with each new item being added to the next empty cell below the existing data on the list. You need to find that next empty cell before you paste your copy!

Sub DataList()
'To run you need a data list on Sheet1.
'A lable in A1 on sheet2.
'Select data on sheet1 and run this code.

'Copy the current selection on Sheet1 &
'amend paste selection to bottom of data
'list on Sheet2.

'Copy current selection from data list.
Sheets("Sheet1").Select
Selection.Copy
'Go to Sheet2, find next empty cell to paste to on the new list.
Sheets("Sheet2").Select
ActiveSheet.Range("A65536").End(xlUp).Offset(1, 0).Select
ActiveSheet.Paste

'Go back to Sheet1.
Sheets("Sheet1").Select
Range("A1").Select
End Sub

You should now be able to fix your code, with this simple addition. Hope this helps. JSW
Joe Was is offline   Reply With Quote
Old Mar 21st, 2002, 09:56 AM   #5
Beckwa
New Member
 
Join Date: Mar 2002
Location: Northampton, UK
Posts: 33
Default

Ok that problems sorted but now there's another problem!!! Now the next line is entered where it should but there's a Total costs section underneath the table which needs to move down a row everytime a new line of information is entered. But then the formula which adds up all the numbers in that column doesn't work. I've been doing macros all day and have lost all sense can u tell!! If anyone can help it would be hugely appreciated!!!!
Beckwa 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 04:39 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