numeric value, vba to split out one digit per column

  • Thread starter Thread starter Revenue
  • Start date Start date
R

Revenue

A previous thread did not address this part of my question.

I have a series of numbers that have to be put on an excel paper form
I designed to match the original. It has a box for each digit of the
respective dollar amounts.

Consider the following three numbers, which are 25000.25, 6050.79,
379.27.
Obviously they must line up on the appropriate cents columns first, so
their placement will vary depending on the size of the number
involved. Essentially, the numbers above would look like this when the
routine finishes:

2 5 0 0 0 2 5
6 0 5 0 7 9
3 7 9 2 7
No decimals as you can see. The total which will be below does not
need to calculate from these converted digits, as it will be derived
separately, and placed on the total line.

What should the loop look like that places these three items. Just
assume for now, the those numbers above are in Ranges, we'll say
Amta1, Amta2, and Amta3.

I appreciate the help.


Bruce
 
Revenue said:
A previous thread did not address this part of my question.

I have a series of numbers that have to be put on an excel paper form
I designed to match the original. It has a box for each digit of the
respective dollar amounts.

Consider the following three numbers, which are 25000.25, 6050.79,
379.27.
Obviously they must line up on the appropriate cents columns first, so
their placement will vary depending on the size of the number
involved. Essentially, the numbers above would look like this when the
routine finishes:

2 5 0 0 0 2 5
6 0 5 0 7 9
3 7 9 2 7
No decimals as you can see. The total which will be below does not
need to calculate from these converted digits, as it will be derived
separately, and placed on the total line.

What should the loop look like that places these three items. Just
assume for now, the those numbers above are in Ranges, we'll say
Amta1, Amta2, and Amta3.

I appreciate the help.


Bruce


A little impatient, are we?

see your original thread
 
A previous thread did not address this part of my question.

Actually, your question has been answered in the other thread. That thread
got kind of long, so instead of making you search for it, here are the two
functions I posted there. This first addresses your specific question for a
9-column print out...

Sub ParseAmountsNewRick()
Dim Cell As Range
For Each Cell In Selection
Cell.Offset(, 1).Resize(, 9) = Split(Format(Replace(Replace( _
Format$(Cell.Value, "0.00"), ".", ""), ",", ""), _
"@_@_@_@_@_@_@_@_@"), "_")
Next
End Sub

and this one, a generalized solution, which allows you to specify any size
for the number of columns via the Size constant (the Const statement)...

Sub ParseAmountsNewRickToo()
Dim Cell As Range
Const Size As Long = 11
For Each Cell In Selection
Cell.Offset(, 1).Resize(, Size) = Split(Format(Replace(Replace( _
Format$(Cell.Value, "0.00"), ".", ""), ",", ""), _
Mid(Replace(String(Size, "@"), "@", "_@"), 2)), "_")
Next
End Sub

You might find it interesting that the statement inside the For..Next block
is only one line long... I used line continuation characters to split the
code line over three physical lines because it is so long (and to stop the
newsgroup parser from word-wrapping it at awkward locations).

Rick Rothstein (MVP - Excel)
 
Back
Top