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 21st, 2002, 08:56 AM   #1
Pumpkinjack
New Member
 
Join Date: May 2002
Posts: 5
Default

Hi Everybody:

First, what a great site, it has helped me a lot in the past, THANK YOU MR. EXCEL!
Here is my quandry. I need to set up an internal PO template for my department. I would like to have a cell generate a PO number automatically upon opening the workbook. Preferably, I would like the number to consist of the current date and a number that will sequentially change each time I open up a new PO. Example:

Today's date is 5/21/02
I would like to have a PO Number generate automatically as 52102-1
Then, after I save the PO, the PO number cell would automatically change to 52102-2
and so on.

Is there such a formula? I can usually get around with basic formulas requests but I cannot figure this out for the life of me. If anyone has any ideas, please post.

Thanks!
Pumpkinjack is offline   Reply With Quote
Old May 21st, 2002, 09:25 AM   #2
Ian Mac
MrExcel MVP
 
Join Date: Feb 2002
Location: Newcastle, UK
Posts: 1,174
Default

Quote:
On 2002-05-21 07:56, Pumpkinjack wrote:
Hi Everybody:

First, what a great site, it has helped me a lot in the past, THANK YOU MR. EXCEL!
Here is my quandry. I need to set up an internal PO template for my department. I would like to have a cell generate a PO number automatically upon opening the workbook. Preferably, I would like the number to consist of the current date and a number that will sequentially change each time I open up a new PO. Example:

Today's date is 5/21/02
I would like to have a PO Number generate automatically as 52102-1
Then, after I save the PO, the PO number cell would automatically change to 52102-2
and so on.

Is there such a formula? I can usually get around with basic formulas requests but I cannot figure this out for the life of me. If anyone has any ideas, please post.

Thanks!
There isn't such a formula. You need to use VBA. If your comfortable trying it........

Goto View>Toolbars>Visual Basic

Click on the Visual Basic Editor button Next to the Hammer and Spanner Button.

With the Editor open find a something titled

VBAProject(TheNameOfYourFile)

Under that Double Click on the ThisWorkbook icon.

Note: If this is not visible click on the + signs until you find it.

Now you should have:

Private Sub Workbook_Open()

End Sub

Copy the following within the 2 lines.

----------------------------------------

If Left(Sheet1.Range("a1").Value, 6) = Format(Now(), "mmddyy") Then

Sheet1.Range("a1").Value = Left(Sheet1.Range("a1").Value, 6) & "-" & Format(Right(Sheet1.Range("a1").Value, 2) + 1, "00")

Else

Sheet1.Range("a1").Value = Format(Now(), "mmddyy") & "-01"

End If

----------------------------------------

you should now have:


Private Sub Workbook_Open()

If Left(Sheet1.Range("a1").Value, 6) = Format(Now(), "mmddyy") Then

Sheet1.Range("a1").Value = Left(Sheet1.Range("a1").Value, 6) & "-" & Format(Right(Sheet1.Range("a1").Value, 2) + 1, "00")

Else

Sheet1.Range("a1").Value = Format(Now(), "mmddyy") & "-01"

End If

End Sub


This should be what you need, by the way I changed the 52102 to 052102 which made it easier for me to write.

Also change the "A1" to which ever you need, and you can change the Sheet1 also baring in mind that Sheet1 is the name that Excel gives the sheet NOT you.

If you have any problems post back.

_________________
Share the wealth!!
Ian Mac

[ This Message was edited by: Ian Mac on 2002-05-21 08:26 ]
Ian Mac is offline   Reply With Quote
Old May 21st, 2002, 09:50 AM   #3
Pumpkinjack
New Member
 
Join Date: May 2002
Posts: 5
Default

Thanks Ian!

Yes that worked but there's a small problem. When I close out of a PO that is finished, and then go back and reopen the same PO, the PO number changes itself.

Example:
I create PO number 052102-01. Save the PO.
Close out of Excel.
Reopen the completed PO #052102-01. The PO number changes automatically again to 052102-02.

Again, the solution you sent is a godsend, thank you so much Ian! But now I this new unplanned problem. Any other ideas. Or is it better to disable the macros whenever I open up a finished PO.

I hope I did not come across as ungrateful, that was not my intention at all.

Peter
Pumpkinjack is offline   Reply With Quote
Old May 21st, 2002, 10:06 AM   #4
Ian Mac
MrExcel MVP
 
Join Date: Feb 2002
Location: Newcastle, UK
Posts: 1,174
Default

Quote:
On 2002-05-21 08:50, Pumpkinjack wrote:
Thanks Ian!

Yes that worked but there's a small problem. When I close out of a PO that is finished, and then go back and reopen the same PO, the PO number changes itself.

Example:
I create PO number 052102-01. Save the PO.
Close out of Excel.
Reopen the completed PO #052102-01. The PO number changes automatically again to 052102-02.

Again, the solution you sent is a godsend, thank you so much Ian! But now I this new unplanned problem. Any other ideas. Or is it better to disable the macros whenever I open up a finished PO.

I hope I did not come across as ungrateful, that was not my intention at all.

Peter
not ungreatful at all, from small acorns and all that.

I'm assuming your changing the name once any work has been done.
What about something like:

Private Sub Workbook_Open()

If ThisWorkbook.Name = "PO Number.xls" Then

If Left(Sheet1.Range("a1").Value, 6) = Format(Now(), "mmddyy") Then

Sheet1.Range("a1").Value = Left(Sheet1.Range("a1").Value, 6) & "-" & Format(Right(Sheet1.Range("a1").Value, 2) + 1, "00")

Else

Sheet1.Range("a1").Value = Format(Now(), "mmddyy") & "-01"

End If

Else

End If

End Sub

ALSO you could get the workbook to save automatically, with:

Private Sub Workbook_Open()

If ThisWorkbook.Name = "PO Number.xls" Then

If Left(Sheet1.Range("a1").Value, 6) = Format(Now(), "mmddyy") Then

Sheet1.Range("a1").Value = Left(Sheet1.Range("a1").Value, 6) & "-" & Format(Right(Sheet1.Range("a1").Value, 2) + 1, "00")

Else

Sheet1.Range("a1").Value = Format(Now(), "mmddyy") & "-01"

End If

ThisWorkbook.SaveAs "C:PO Number_" & Sheet1.Range("A1").Value

Else

End If

End Sub

Change the location as required.


__________________
"Have a good time......all the time"
Ian Mac
Ian Mac is offline   Reply With Quote
Old May 21st, 2002, 10:36 AM   #5
Pumpkinjack
New Member
 
Join Date: May 2002
Posts: 5
Default

Ian you are such a life saver!!

I like the idea of the automatic save. When I put in the "VBA stuff", save it then go back to open the file, I get the following:

Run Time error '1004':

The file could not be accessed

Then I hit debug button and the following line gets highlighted:

ThisWorkbook.SaveAs "C:\PO Number_" & Sheet1.Range("a1").Value

Did I type something wrong? I apologize for being so dense.

Also, if I was to change all the "A1" entries to say "B2", would the result appear in the B2 cell?

Thank you again Ian!

Best regards,
Peter the Excel Impaired
Pumpkinjack is offline   Reply With Quote
Old May 22nd, 2002, 04:15 AM   #6
Ian Mac
MrExcel MVP
 
Join Date: Feb 2002
Location: Newcastle, UK
Posts: 1,174
Default

Quote:
On 2002-05-21 09:36, Pumpkinjack wrote:
Ian you are such a life saver!!

I like the idea of the automatic save. When I put in the "VBA stuff", save it then go back to open the file, I get the following:

Run Time error '1004':

The file could not be accessed

Then I hit debug button and the following line gets highlighted:

ThisWorkbook.SaveAs "C:\PO Number_" & Sheet1.Range("a1").Value

Did I type something wrong? I apologize for being so dense.

Also, if I was to change all the "A1" entries to say "B2", would the result appear in the B2 cell?

Thank you again Ian!

Best regards,
Peter the Excel Impaired
Yes you can change A1 to B1

as for the other, it appears that if you put a backslash on the board you get 2.

You need to put

ThisWorkbook.SaveAs "C:ONE backslash herePO Number_" & Sheet1.Range("a1").Value

You can also change the path (remember for each double backslash, one)

ThisWorkbook.SaveAs "C:first folder namesecond folder namePO Number_" & Sheet1.Range("a1").Value

__________________
"Have a good time......all the time"
Ian Mac
Ian Mac is offline   Reply With Quote
Old May 22nd, 2002, 06:26 AM   #7
Pumpkinjack
New Member
 
Join Date: May 2002
Posts: 5
Default

I said it before and I'll say it again, Ian you are a life saver!!

Thank you so much for your help!!

Best regards,
Pete
Pumpkinjack is offline   Reply With Quote
Old Feb 11th, 2011, 08:43 AM   #8
louis reichert
New Member
 
Join Date: Feb 2011
Posts: 2
Default Re: Automatic PO numbering help

I am trying to do the same peter did but I cannot get it to work please help
louis reichert 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:31 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