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 Feb 27th, 2002, 09:25 PM   #1
latecomer
New Member
 
Join Date: Feb 2002
Posts: 2
Default

Hello
is there a way in excel 2000 to generate a running number? eg a unique (in running order) number for purchase order form
latecomer is offline   Reply With Quote
Old Feb 27th, 2002, 10:02 PM   #2
Tom Urtis
MrExcel MVP
 
Tom Urtis's Avatar
 
Join Date: Feb 2002
Location: San Francisco, California USA
Posts: 10,382
Default

There are many ways to do this, depending on what event you prefer that will generate a unique number.

Here is an example of a unique number being placed into cell A1 of Sheet1, by incrementing whatever number is in there by 1 each time the workbook opens.

Locate the Excel workbook icon that is just to the left of the "File" worksheet menu option, near the upper left corner of your screen. Right click on that icon, then left click on View Code, and paste this in:

Private Sub Workbook_Open()
Sheet1.[A1] = Sheet1.[A1] + 1
End Sub

Modify for sheet and cell reference.

This same effect can be accomplished by other means, such as whenever a sheet is activated, or the invoice gets printed, or a certain cell is filled with a certain value, etc. This example though, should get you started.

Tom Urtis
Tom Urtis is offline   Reply With Quote
Old Feb 28th, 2002, 09:15 AM   #3
latecomer
New Member
 
Join Date: Feb 2002
Posts: 2
Default

thanks Tom. much appreciated. do u think I can add a text to the number? eg 001/it/md.
latecomer is offline   Reply With Quote
Old Mar 1st, 2002, 05:23 PM   #4
Tom Urtis
MrExcel MVP
 
Tom Urtis's Avatar
 
Join Date: Feb 2002
Location: San Francisco, California USA
Posts: 10,382
Default

Yes this can be done, and here is what I would recommend for your situation. My experience has been that most people find that it is easier to edit formulas than to edit VBA code. At least with a formula, if edited incorrectly, the worst case outcome will be a cell or cells that have error displays or incorrect calculations. Not a good scenario, but still not as bad as a VBA code that is edited incorrectly, which may stop an entire workbook in its tracks. And, there are only 3 cells totally involved here.

So, I told you that story to tell you this one:

Consider this suggestion -- replace the Workbook_Open code I posted originally with this instead:

Private Sub Workbook_Open()
Sheet1.[A1] = _
Sheet1.[B1] & _
"/" & _
Sheet1.[C1]
End Sub

Remember, right click on the Excel workbook icon to the left of the File menu, then left click on View Code, and paste this in.

Now, in cell B1, enter the formula
=TEXT(LEFT(A1,3)+1,"000")

And in C1 enter the formula
=RIGHT(A1,LEN(A1)-SEARCH("/",A1))

And to get off on the right foot, in cell A1 of Sheet1, enter the value
001/it/md

The reason for all this effort at the outset is based in my belief (and I could be mistaken but this is my experience) that having the formulas determine what you want displayed, instead of the VBA code, will be easier to maintain for most people. All this stuff can be wrapped up in VBA code, but when someone besides you must edit this file, changing the formulas might be more intuitive for them.

Sorry for this long-winded answer, but your solution involved leading zeros, with incrementing numbers combined with text in one string. I took your reply to mean that the first 3 characters of the cell will be numerals that should increase by 1 each time the workbook opens.

You can modify the code by referncing cells other than B1 or C1, depending on where you want toplace those formulas, preferably out of sight and protected.

Hope this helps.

Tom Urtis
Tom Urtis is offline   Reply With Quote
Old Sep 15th, 2009, 08:23 PM   #5
WhatEverInMind
New Member
 
Join Date: Sep 2009
Posts: 1
Default Re: self generate a running number

Hi Tom,
Basically i'm using excel 2007. If i want to use the same code to produce my purchase order, is there any problem for that? And how to input the code into it?
WhatEverInMind 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 07:24 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