Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

strange number conversion

Status
Not open for further replies.

impulse24

IS-IT--Management
Jul 13, 2001
167
US
Hi,

I have a customer who is sending me numeric values from 1-234. They then want me to convert those values to alpha & numeric.

1 = 1A
2 = 1B
27 = 2A

The number goes from 1-26 and has A-Z, then when it gets to 27 it goes to 2A - 2Z, and so on. I can't seem to figure out the conversion table. Please help
 
Something like
[blue][tt]
AlphaCode = Trim$(Str$(((Number \ 27) + 1 ))) & Chr$((Number MOD 26) + 64)
[/tt][/blue]?
 
impulse,

I entered this formula in A1 on an Excel spreadsheet and copied down
[tt]
=INT((ROW()-1)/26)+MOD(ROW()-1,26)+1&CHAR(MOD(ROW()-1,26)+65)
[/tt]
So if you want to use code rather than a spreadsheet, substitute the Numeric Value to convert for ROW()
Code:
ConVal = Int((NumVal - 1) / 26) + (NumVal - 1) Mod 26 + 1 & Chr((NumVal - 1) Mod 26 + 65)
:)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
thanks for the help golom..it almost works, but when I have 26 it produces 1@, and 234 produces 9@, so it looks like anytime the value should be Z it is using a @.
Skip, i tried yours but the result for 26 was 26Z instead of 1Z, not sure where it went wrong
 
duh! sorry
[tt]
=INT((ROW()-1)/26)+1&CHAR(MOD(ROW()-1,26)+65)
[/tt]
Code:
ConVal = Int((NumVal - 1) / 26)  & Chr((NumVal - 1) Mod 26 + 65)


Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
OK. I guess it needs to be
[blue][tt]
AlphaCode = Trim$(Str$(((Number \ 27) + 1 ))) & _
Chr$(IIF(Number MOD 26=0,1, Number MOD 26) + 64)
[/tt][/blue]
 
SkipVought, you almost had it the second time....try this...

ConVal = Int((NumVal + 1) / 26) & Chr((NumVal - 1) Mod 26 + 65)
 
Yea, I missed the + 1 -- and NOTICE the place...
Code:
ConVal = Int((NumVal - 1) / 26) + 1 & Chr((NumVal - 1) Mod 26 + 65)


Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Yeah, I just figured that out....DOH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top