# coding if logic on number pattern

Dear experts,

I am a bit new to Excel 2007 and I am trying to figure out how to create a formula to add 7 to the previous number if the number in the tens place is not the same as the previous number in the tens place. If it is then add 17 to the code. Here is a sample number pattern:

0026
0033
0040
0057
0064
0071
0088
0095
0101
0118
0125
0132
0149
0156
0163
0170
0187
0194
0200

I am entering a ton of certified mail tickets and seems the last four of the ticket number has this pattern. Knowing a formula to autofill would save me a ton of time.

I have attached a sample spreadhsheet. I could easily code a formula to add seven but get stuck when I try to if logic to check the tens place.

Thanks!

Certified-Reciepts.xlsx
###### Who is Participating?

ConsultantCommented:
This should work:

=D2+7+IF(TRUNC((D2+7)/10)-TRUNC(D2/100)*100=TRUNC(D2/10)-TRUNC(D2/100)*100,10,0)

Kevin
0

ConsultantCommented:
See the attached. Did I interpret your question correctly?

Kevin
Certified-Reciepts.xlsx
0

Author Commented:
zorvek:

No. Please see screenshot. The tens place apparently cannot repeat. I suppose if the formula is correct you could type 0026 in the first cell and then use the formula populate subsequent cells and the numbers under D should be identical.
excel-screenshot.jpg
0

Author Commented:
Cool! Thanks!
0

ConsultantCommented:
See attached.

Kevin
Certified-Reciepts.xlsx
0

Commented:
Here's a shorter option

=D2+7+(MOD(D2,10)<3)*10

regards, barry
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.