Excel Help Forum
ExcelTip.com
Account Icon Account Icon Account Icon
ExcelTip.com

Go Back   Excel Help Forum > Microsoft Office Application Help - Excel Help forum > Excel Programming > Excel Worksheet Functions

Reply
 
Thread Tools Display Modes
  #1  
Old 04-30-2007, 12:15 AM
xcentric xcentric is offline
Registered User
 
Join Date: 30 Apr 2007
Posts: 1
xcentric is becoming part of the community
Question How do you auto number?

I want to auto number a spreadsheet but I can't seem to get the formula right. I want to number the rows based on the neighboring cells. If the first name and last name match then number it the same then move on. Can someone help me in the right direction please? I would like the numbering to look like this:

1 John Doe
1 John Doe
2 Jane Doe
3 Frank Johnson
4 Ralph Smith
4 Ralph Smith
4 Ralph Smith

Last edited by xcentric; 04-30-2007 at 12:28 AM.
Reply With Quote
  #2  
Old 04-30-2007, 01:36 AM
BigBas BigBas is offline
Forum Guru
 
Join Date: 12 Jan 2007
Location: New Jersey
Posts: 1,535
BigBas is becoming part of the community
This is one way to do it:

I put a number 1 in the first row. Then in cell A2 (this is assuming the numbers are in column A, and names in B):

Code:
=IF(B2="","",IF(COUNTIF($B$1:B2,B2)>1,INDEX($A$1:A1,MATCH(B2,$B$1:$B$100,0)),MAX($A$1:A1)+1))
Try that and let me know if it works.

EDIT to add: You can fill that formula down as far as necessary. If there is no name in the corresponding cell in column B, it will return blank.
Reply With Quote
  #3  
Old 04-30-2007, 04:58 AM
olasa olasa is offline
Forum Guru
 
Join Date: 24 Dec 2004
Location: Sweden
Posts: 1,079
olasa is becoming part of the community
Increment by one

If the names are entered in identical ways, meaning that John Doe is not written John, Doe or Doe, John, the below can be used.

I let the names start in A1, so I put 1 in B1.
Then I put =B1--(A1<>A2) in B2, and copy the formula downward.
Done

//Ola

Code:
John Doe           1                  -->1
John Doe           =B1--(A1<>A2)       -->1
Jane Doe           =B2--(A2<>A3)       -->2
Frank Johnson     ....                       
Ralph Smith
Ralph Smith
Ralph Smith
Reply With Quote
  #4  
Old 04-30-2007, 10:25 AM
BigBas BigBas is offline
Forum Guru
 
Join Date: 12 Jan 2007
Location: New Jersey
Posts: 1,535
BigBas is becoming part of the community
Quote:
Originally Posted by olasa
If the names are entered in identical ways, meaning that John Doe is not written John, Doe or Doe, John, the below can be used.

I let the names start in A1, so I put 1 in B1.
Then I put =B1--(A1<>A2) in B2, and copy the formula downward.
Done

//Ola

Code:
John Doe           1                  -->1
John Doe           =B1--(A1<>A2)       -->1
Jane Doe           =B2--(A2<>A3)       -->2
Frank Johnson     ....                       
Ralph Smith
Ralph Smith
Ralph Smith
Olasa.... Interesting formula; however, I don't think that would work if the names were out of order. For example, if John Doe was added again after Ralph Smith, it would assing him a brand new number. Is there a way around that using your setup.
Reply With Quote
  #5  
Old 04-30-2007, 09:18 PM
olasa olasa is offline
Forum Guru
 
Join Date: 24 Dec 2004
Location: Sweden
Posts: 1,079
olasa is becoming part of the community
...assumption/method...

Thanks BigBas, yea well they way xcentric presented the problem, I assumed he would sort the list, which would lead to no blanks. And it would help him keep a "consistancy"; 'John Doe' would not become 'John, Doe' or 'John Doe_'.

xcentric has to answer but if the first assumption is wrong I would stick with your proposal* and if the second assumption is wrong I'd use the method of first clear all spaces and commas.

But if the inconsistancy is - call it - 'level three difficulty', meaning 'John Doe could also be 'Doe, John ', the pattern recognition would have to be steped up bit more.

But all in all, let's hope that one of the proposed options suit xcentric, and if not, we'll see if we can find another way.

//Ola


...This line of resoning might help xcentric to forsee some future problems

* ...BigBas I just read you last question, could my setup be used if John Doe was added at the end...sure if the formula (in B2) is changed to: =B1+MIN(--(A2<>$A$1:A1)) and entered as an 'array formula';
xcentric: type the formula but don't hit enter. Instead hold down Ctrl and Shift and then hit Enter. If Excel now has added two squiggly brackets { } around the formula, it should work.
Reply With Quote
  #6  
Old 04-30-2007, 09:25 PM
mikerickson mikerickson is offline
Forum Moderator
 
Join Date: 30 Mar 2007
Location: Davis CA
MS Office Version:Excel 2004
Posts: 2,020
mikerickson has an addiction to Excel
in A2

=IF(B2=B1,A1,A1+1)

works for me.

Last edited by mikerickson; 04-30-2007 at 09:31 PM.
Reply With Quote
  #7  
Old 04-30-2007, 11:42 PM
BigBas BigBas is offline
Forum Guru
 
Join Date: 12 Jan 2007
Location: New Jersey
Posts: 1,535
BigBas is becoming part of the community
Quote:
Originally Posted by olasa
* ...BigBas I just read you last question, could my setup be used if John Doe was added at the end...sure if the formula (in B2) is changed to: =B1+MIN(--(A2<>$A$1:A1)) and entered as an 'array formula';
xcentric: type the formula but don't hit enter. Instead hold down Ctrl and Shift and then hit Enter. If Excel now has added two squiggly brackets { } around the formula, it should work.
Ola... Your strength and understanding of the array formulas never ceases to amaze me. Nevertheless, your formula did not work for me (unless either we have a misunderstanding or I have done something wrong). Assuming the list is NOT sorted, let's use the data you have previously supplied. If John Doe repeats at the end of the list, out of order with the other John Doe, it does not assume the same number as previous John Doe. It is assigned the same number as the last entry. Does that make sense?
Reply With Quote
  #8  
Old 05-01-2007, 05:52 PM
olasa olasa is offline
Forum Guru
 
Join Date: 24 Dec 2004
Location: Sweden
Posts: 1,079
olasa is becoming part of the community
Thanks but

Thanks for the compliment BigBas, but I missed your point - that all John Doe should have the same number. I can hardly blame the IRS and late night for diverting my focus (it's due tomorrow here). So to do what your meant, I would basically use the same formula.

//Ola

Code:
=IF(COUNTIF($A$1:A1,A2)=0,MAX($B$1:B1)+1,VLOOKUP(A2,$A$1:B1,2,0))
Reply With Quote
Reply

Bookmarks

New topics in Excel Worksheet Functions


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump


All times are GMT -4. The time now is 08:58 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0