View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Custom HEX or BASE 33 Sequence

The output is correct... it just appears to not be what you are now looking
for. Your original post asked for a method of generating consecutive Base33
numbers... the formula I posted will allow you to do that... it returns the
next Base33 number after the one that was passed into it... it is not a
decimal number to Base33 number converter (which your new object of "I want
a function that is identical to DEC2HEX but uses my custom base33 sequence"
indicates you now want)... it is simply an incrementer of Base33 numbers.
The next Base33 number after 0010 is 0011 (decimal 34 follows decimal 33) in
the same way that the next Hex number after 10 is 11 (because decimal 17
follows decimal 16).

Okay, so you want a Decimal to Base33 converter. Try this UDF...

Public Function Dec2Base33(Value As Long, Optional _
NumLen As Long = 0) As String
Dim Modulo As Long
Dim Result As Long
Const Digits = "0123456789ABCDEFGHJKLMNPQRSTVWXYZ"
Do Until Value = 0
Modulo = Value Mod 33
Dec2Base33 = Mid(Digits, Modulo + 1, 1) & Dec2Base33
Value = Value \ 33
Loop
If NumLen 0 Then Dec2Base33 = Right(String(NumLen, "0") & _
Dec2Base33, NumLen)
If Dec2Base33 = "" Then Dec2Base33 = "0"
End Function

--
Rick (MVP - Excel)


"Mitch Matheny" wrote in message
...
Rick, I can't seem to get the code to work properly. If I type in 0009 I
get
000A which is ok, then I type in 0010 and I get 0011 which is not correct.
Not sure what I am doing wrong. I think I got off course by saying I
wanted
my list to start at 0001. That really doesn't matter.

Let me restate my objective. I want a function that is identical to
DEC2HEX
but uses my custom base33 sequence.

So if I type the decimal number 0 (in cell A1 for example) I get 0000 (in
cell A2 for example). Other random examples:

Input = Output
0 = 0000
9 = 0009
10 = 000A
33 = 0010
18 = 000J
43 = 001A
???????? = ZZZZ (not sure what it would take to get ZZZZ, I will probably
never need to go this high, but would like to have the capability to
calculate the complete sequence if needed.)

My original question asked for a column of my sequence because I was going
to use a VLOOKUP to calculate decimal to base33. After seeing the last two
postings I think it may be simpler to go another route.

Additional suggestions would be appreciated. Thanks - Mitch

"Rick Rothstein" wrote:

Here is a UserDefinedFunction (UDF) that will increase a Base33 number by
one...

Public Function AddOneBase33(Base33Value As Variant) As String
Dim X As Long
Const Digits = "0123456789ABCDEFGHJKLMNPQRSTVWXYZ0"
AddOneBase33 = "0" & Base33Value
For X = Len(AddOneBase33) To 1 Step -1
Mid(AddOneBase33, X) = Mid(Digits, InStr(Digits, Mid( _
AddOneBase33, X, 1)) + 1, 1)
If Mid("0" & Base33Value, X, 1) < "Z" Then Exit For
Next
AddOneBase33 = Mid(AddOneBase33, 2)
End Function

To use it, simple enter your starting Base33 number, as a **text** value,
in
a cell, say '0000 in A1; then use the UDF with that cell as a reference.
So,
this...

=AddOneBase33(A1)

will result in 0001. You can copy this formula down to generate your
sequence of numbers. Of course, read Harlan's post about the limitation
problem you will have in trying to get to ZZZZ.

Oh, in case you don't know how to install an UDF... press Alt+F11 to get
into the VBA editor, click Insert/Module from the menu bar there,
copy/paste
the code above into the code window that appears. That's it... the UDF
can
now be used on your worksheet.

--
Rick (MVP - Excel)


"Mitch Matheny" wrote in message
...
I want to create a custom numbering sequence in excel....

0123456789ABCDEFGHJKLMNPQRSTVWXYZ
(note that the letters I, O, & U are left out).

My objective is to create a column of the custom sequence that looks
like
the following...

0001
0002
0003
0004
0005
0006
0007
0008
0009
000A
000B

all the way to

ZZZZ

of course minus the letters I, O, & U.

If this is possible, I would appreciate any help I can get. Thanks, -
Mitch