Actuarial Outpost
 
Go Back   Actuarial Outpost > Actuarial Discussion Forum > Software & Technology
FlashChat Actuarial Discussion Preliminary Exams CAS/SOA Exams Cyberchat Around the World Suggestions

ACTUARIAL SALARY SURVEYS

Reply
 
Thread Tools Display Modes
  #1  
Old 10-10-2004, 08:03 PM
Zorro Zorro is offline
Member
 
Join Date: Jun 2004
Posts: 1,320
Default Excel: checking for sequential numbering

I have an export from a database in Excel. Each record has a unique identifier. I would like to make sure the records are in a sorted order and each identifier is 1+identifier of the previous record.

Or, an example:
Code:
5 Apple
6 Orange
7 Banana
8 Monkey
I would like to do this in a single cell, ie without inserting a row. It should evaluate to TRUE (everything OK) or FALSE (record missing, duplicate etc.)

Anyone?
Reply With Quote
  #2  
Old 10-10-2004, 08:15 PM
Utanapishtim's Avatar
Utanapishtim Utanapishtim is offline
Member
CAS
 
Join Date: Jan 2004
Location: BC
Posts: 3,088
Default

I don't have Excel in front of me, but...
For numbers in A1 to A100, how about:
{If(OR(max(A2:A100 - A1:A99) > 1, min(A2:A100 - A1:A99) < 1),FALSE,TRUE)}
Reply With Quote
  #3  
Old 10-10-2004, 08:20 PM
Brad Gile's Avatar
Brad Gile Brad Gile is offline
Member
CAS SOA AAA
 
Join Date: Sep 2001
Studying for whatever I feel like
College: Alumnus of Brown and UW-Madison
Posts: 11,107
Default Re: Excel: checking for sequential numbering

Quote:
Originally Posted by Zorro
I have an export from a database in Excel. Each record has a unique identifier. I would like to make sure the records are in a sorted order and each identifier is 1+identifier of the previous record.

Or, an example:
Code:
5 Apple
6 Orange
7 Banana
8 Monkey
I would like to do this in a single cell, ie without inserting a row. It should evaluate to TRUE (everything OK) or FALSE (record missing, duplicate etc.)

Anyone?
Public Function IsOrdered(R As Range) As Boolean
'Unique record identifier is a (long) integer
'in Column 1

Dim J As Long
Dim Result As Boolean

Result = True 'set as Default

For J = 2 To R.Rows.Count
If R(J, 1) <> R(J - 1, 1) + 1 Then
Result = False
Exit For
End If
Next J

IsOrdered = Result

End Function

Am I missing something?

Brad
__________________
Brad Gile, FSA, MAAA
Affiliate Member of the CAS
Dedicated Retired Actuary

Spoiler:
Obama sucks and we all know it-TDA


Spoiler:

That's been the funniest subplot of this whole thing, the people on the left attacking this bill for not being even more of a steaming pile. - erosewater
Reply With Quote
  #4  
Old 10-10-2004, 09:25 PM
Zorro Zorro is offline
Member
 
Join Date: Jun 2004
Posts: 1,320
Default

I forgot to mention a strong preference for a non-VBA solution. (What they don't understand....)

Quote:
Originally Posted by Utanapishtim
I don't have Excel in front of me, but...
For numbers in A1 to A100, how about:
{If(OR(max(A2:A100 - A1:A99) > 1, min(A2:A100 - A1:A99) < 1),FALSE,TRUE)}
Thanks, that put me on the right track! I now check if
- last number = first number + number of records - 1
- MAXA(OFFSET(A7,,,B3,1)-OFFSET(A6,,,B3,1) equals 1
Where the data starts at A6 and B3 contains the number of records
Reply With Quote
  #5  
Old 10-11-2004, 09:34 AM
Brad Gile's Avatar
Brad Gile Brad Gile is offline
Member
CAS SOA AAA
 
Join Date: Sep 2001
Studying for whatever I feel like
College: Alumnus of Brown and UW-Madison
Posts: 11,107
Default

Quote:
Originally Posted by Zorro
I forgot to mention a strong preference for a non-VBA solution. (What they don't understand....)


Brad
__________________
Brad Gile, FSA, MAAA
Affiliate Member of the CAS
Dedicated Retired Actuary

Spoiler:
Obama sucks and we all know it-TDA


Spoiler:

That's been the funniest subplot of this whole thing, the people on the left attacking this bill for not being even more of a steaming pile. - erosewater
Reply With Quote
  #6  
Old 10-11-2004, 12:27 PM
Hedges Hedges is offline
Member
SOA
 
Join Date: Apr 2002
Location: Shanghai
Posts: 313
Default

Zorro, how about the following?

Assuming your record identifiers are in cells C4:C8, then
{=SUM((((C5:C8)-(C4:C7))=1)*1)}
(Don't forget to enter as an array formula)

This counts the number of differences between sequential records that equal 1. If all your identifiers are sequential, then the result will be one less than the number of records, so you could modify it to the following
{=SUM((((C5:C8)-(C4:C7))=1)*1)-COUNT(C4:C8)+1}
In this case, anything other than a zero is problem.

Is this what you are looking for?

Hedges
Reply With Quote
  #7  
Old 10-11-2004, 01:30 PM
Utanapishtim's Avatar
Utanapishtim Utanapishtim is offline
Member
CAS
 
Join Date: Jan 2004
Location: BC
Posts: 3,088
Default

Quote:
Originally Posted by Zorro
Quote:
Originally Posted by Utanapishtim
I don't have Excel in front of me, but...
For numbers in A1 to A100, how about:
{If(OR(max(A2:A100 - A1:A99) > 1, min(A2:A100 - A1:A99) < 1),FALSE,TRUE)}
Thanks, that put me on the right track! I now check if
- last number = first number + number of records - 1
- MAXA(OFFSET(A7,,,B3,1)-OFFSET(A6,,,B3,1) equals 1
Where the data starts at A6 and B3 contains the number of records
The trouble with just checking that is that if you have two numbers reversed somewhere in the middle, for example, it won't show up. Or any arrangement of the numbers in the middle, actually, as long as they're all there and the first and last are correct, right?
Reply With Quote
  #8  
Old 10-11-2004, 02:38 PM
snafu's Avatar
snafu snafu is offline
Member
CAS
 
Join Date: Nov 2001
Location: no longer on a small Island
Posts: 2,547
Default

Assuming cells A2 through A7 contain the numbers 1 through 6

Then Cell A1 = {=AND((A2:A6 + 1) = A3:A7)}

Enter this as an array function by using Shift-Ctrl-Enter

Bon Appetit!
__________________
Emoticon Contest winner
ACOOP III Main Event Winner and Overall Money Champion
Reply With Quote
  #9  
Old 10-11-2004, 05:32 PM
Zorro Zorro is offline
Member
 
Join Date: Jun 2004
Posts: 1,320
Default

Quote:
Originally Posted by Utanapishtim
Quote:
Originally Posted by Zorro
Quote:
Originally Posted by Utanapishtim
I don't have Excel in front of me, but...
For numbers in A1 to A100, how about:
{If(OR(max(A2:A100 - A1:A99) > 1, min(A2:A100 - A1:A99) < 1),FALSE,TRUE)}
Thanks, that put me on the right track! I now check if
- last number = first number + number of records - 1
- MAXA(OFFSET(A7,,,B3,1)-OFFSET(A6,,,B3,1) equals 1
Where the data starts at A6 and B3 contains the number of records
The trouble with just checking that is that if you have two numbers reversed somewhere in the middle, for example, it won't show up. Or any arrangement of the numbers in the middle, actually, as long as they're all there and the first and last are correct, right?
I might be wrong, but the second condition checks that the increase of the identifier is at most 1. Since, for n records, there needs to be a total increase of n to arrive at the last number (condition 1), each record will have to increase by exactly one.
Reply With Quote
  #10  
Old 10-11-2004, 05:33 PM
Zorro Zorro is offline
Member
 
Join Date: Jun 2004
Posts: 1,320
Default

Quote:
Originally Posted by snafu
Assuming cells A2 through A7 contain the numbers 1 through 6

Then Cell A1 = {=AND((A2:A6 + 1) = A3:A7)}

Enter this as an array function by using Shift-Ctrl-Enter

Bon Appetit!
Very creative!
Reply With Quote
Reply

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 Off


All times are GMT -4. The time now is 06:40 AM.


Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
*PLEASE NOTE: Posts are not checked for accuracy, and do not
represent the views of the Actuarial Outpost or its sponsors.
Page generated in 0.30075 seconds with 7 queries