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 Apr 13th, 2002, 03:59 PM   #1
naq_uk
New Member
 
Join Date: Apr 2002
Location: London, Tottenham
Posts: 8
Default

PLEASE HELP

I am doing a project for college and need some help. I have a sheet that will open on a template but need an auto number to appear in two cells (E3:E4) automatically that are unique each time, preferably sequential. Can some1 help me??????????????
naq_uk is offline   Reply With Quote
Old Apr 13th, 2002, 04:29 PM   #2
daleyman
Board Regular
 
Join Date: Mar 2002
Location: London, UK
Posts: 167
Default

a little vba could fix this, but to verify the request, please confirm my understanding,

each time a sheet is added to the workbook, two new numbers are generated sequentially following the highest value of any value in these two cells from any other sheet???

try this in the workbook module...


Private Sub Workbook_NewSheet(ByVal Sh As Object)
maxval = 0
For sn = 1 To ActiveWorkbook.Sheets.Count
If Sheets(sn).Name <> Sh.Name Then
If IsNumeric(Sheets(sn).Range("e3")) And Sheets(sn).Range("e3") > maxval Then maxval = Sheets(sn).Range("e3").Value
If IsNumeric(Sheets(sn).Range("e4")) And Sheets(sn).Range("e4") > maxval Then maxval = Sheets(sn).Range("e4").Value
End If
Next
Sh.Range("e3") = maxval + 1
Sh.Range("e4") = maxval + 2
End Sub


__________________

<table style="background-color:#0e54be" cellspacing="1" cellpadding="2"><td style="background-color:#ceffff;font-family:arial;color:#072c63;font-size:8pt;">***DALEY** :P**</td></table>
daleyman is offline   Reply With Quote
Old Apr 13th, 2002, 04:38 PM   #3
naq_uk
New Member
 
Join Date: Apr 2002
Location: London, Tottenham
Posts: 8
Default

Thanks for your help. I kind of get it but still am a bit confused. Do i replace Sheets with the name of my sheet. Sorry to inconvenience u but is it possible for you to write it again as before but include the sheet name "invoice" in the appropriate places?? THANKS. I AM VERY GRATEFUL!!!

FELLOW LONDONER!
naq_uk is offline   Reply With Quote
Old Apr 13th, 2002, 04:42 PM   #4
daleyman
Board Regular
 
Join Date: Mar 2002
Location: London, UK
Posts: 167
Default

no, i intended the code for use as-is. it searchs all sheets when you open a new one, and gets two new values sequentially higher than those that appear in the same cells on any other sheet that's already existing in the workbook.

add it to the workbook module of a new book, then keep adding new sheets, you'll see what i mean...
__________________

<table style="background-color:#0e54be" cellspacing="1" cellpadding="2"><td style="background-color:#ceffff;font-family:arial;color:#072c63;font-size:8pt;">***DALEY** :P**</td></table>
daleyman is offline   Reply With Quote
Old Apr 13th, 2002, 04:48 PM   #5
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Quote:
On 2002-04-13 15:29, daleyman wrote:
a little vba could fix this, but to verify the request, please confirm my understanding,

each time a sheet is added to the workbook, two new numbers are generated sequentially following the highest value of any value in these two cells from any other sheet???

try this in the workbook module...


Private Sub Workbook_NewSheet(ByVal Sh As Object)
maxval = 0
For sn = 1 To ActiveWorkbook.Sheets.Count
If Sheets(sn).Name <> Sh.Name Then
If IsNumeric(Sheets(sn).Range("e3")) And Sheets(sn).Range("e3") > maxval Then maxval = Sheets(sn).Range("e3").Value
If IsNumeric(Sheets(sn).Range("e4")) And Sheets(sn).Range("e4") > maxval Then maxval = Sheets(sn).Range("e4").Value
End If
Next
Sh.Range("e3") = maxval + 1
Sh.Range("e4") = maxval + 2
End Sub


__________________
Kind Regards,
Ivan F Moala From the City of Sails
Ivan F Moala is offline   Reply With Quote
Old Apr 14th, 2002, 12:42 AM   #6
nisht
Board Regular
 
Join Date: Feb 2002
Location: Ahmedabad Gujarat
Posts: 303
Default

download the file no 14

http://www.pexcel.com/download.htm

here i have given the example of autonumbering.. or you can say invoicnumbering.

see if it is helpful to you.

file shows how you can use roman nos ..

prefix and suffix numbering ..

here you can even change start nos

it is better if you can see this file.

nishith desai
http://www.pexcel.com
nisht is offline   Reply With Quote
Old Apr 14th, 2002, 08:06 AM   #7
naq_uk
New Member
 
Join Date: Apr 2002
Location: London, Tottenham
Posts: 8
Default

Thanks everyone for your help. It is much appreciated!

Love
Naz
naq_uk is offline   Reply With Quote
Old Apr 15th, 2002, 03:40 PM   #8
naq_uk
New Member
 
Join Date: Apr 2002
Location: London, Tottenham
Posts: 8
Default

so far I have tried the following:

Quote:
On 2002-04-14 07:40, daleyman wrote:
Private Sub Workbook_NewSheet(ByVal Sh As Object)
maxval = 0
For sn = 1 To ActiveWorkbook.Sheets.Count
If Sheets(sn).Name <> Sh.Name Then
If IsNumeric(Sheets(sn).Range("e3")) And Sheets(sn).Range("e3") > maxval Then maxval = Sheets(sn).Range("e3").Value
If IsNumeric(Sheets(sn).Range("e4")) And Sheets(sn).Range("e4") > maxval Then maxval = Sheets(sn).Range("e4").Value
End If
Next
Sh.Range("e3") = maxval + 1
Sh.Range("e4") = maxval + 2
End Sub


...is all you need, take away the extra "Sub AddNewNumber"...the statement:

Private Sub Workbook_NewSheet(ByVal Sh As Object)

...opens the procedure, you need to paste the block of code into the module that relates to the Workbook. NewSheet is the event, therefore, whenever you add a new sheet this macro will run automatically, because excel will look in the Workbook module to see if there is such a procedure.

If you don't know where the Workbook module is, go into the Visual Basic Editor and double click on the "ThisWorkbook" label, this will open up the code sheet for that object.

Good Luck....
_________________

DALEY :P
And this only worked when a new sheet was inserted and not for when a new sheet is opened from a template. So i tried the following:

Quote:
On 2002-04-14 08:15, daleyman wrote:
try putting this code into the "ThisWorkbook" module of the worksheet...


Private Sub Workbook_Open()

val1 = Sheets("Sheet2").Range("E3").Value
val2 = Sheets("Sheet2").Range("E4").Value

If IsNumeric(val1) And IsNumeric(val2) Then
If val1 > val2 Then val3 = val1 Else val3 = val2
Sheets("sheet2").Range("E3").Value = val3 + 1
Sheets("sheet2").Range("E4").Value = val3 + 2
End If

End Sub


...the idea being that every time you open the workbook, it gets the values from cells E3 and E4, and if they are numeric, substitutes them for two new values sequentially higher than the maximum of the two existing values...

_________________

DALEY :P
but this kept giving the same values in e3 and e4 every time i opened a new worksheet from the template.

What should happen is that every time a new sheet is opened from the template a different and unique number should appear in e3 and e4. Any more ideas???

(thanks to Nishith desai! but it only adds a new number going down the column each time!)

Thanks

Naz

[ This Message was edited by: naq_uk on 2002-04-15 14:41 ]
naq_uk 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 11:27 AM.


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