Number formatting into Sets of 3

anthonyexcel

Active Member
Joined
Jun 10, 2011
Messages
258
Office Version
  1. 365
Platform
  1. Windows
I have numbers in column A that look like this
13,065,102
13,165
4,051,065
600
18,013,092

<tbody>
</tbody>



But when I click in the formula bar they are really this (real numbers)
13065102
13165
4051065
600
18013092

<tbody>
</tbody>


What I need to do is to is put the numbers into sets of 3 from right to left
13065102013065102
13165013165
4051065004051065
600600
18013092018013092

<tbody>
</tbody>
 
Hi again
This new code is for general farmat( 123456 or 12,345,3....)
Code:
Sub test()
    Dim a, b As Variant
    lr = Cells(Rows.Count, 2).End(xlUp).Row - 1
    a = Application.Transpose(Range("b2").Resize(lr))
    Application.ScreenUpdating = False
    ReDim b(1 To 1)
    With CreateObject("VBScript.RegExp")
        .Global = True
        .Pattern = "\d{1,3}"
        For i = 1 To lr
            Set Sres = .Execute(a(i))
            ReDim b(1 To Sres.Count)
            For j = 0 To Sres.Count - 1
                b(j + 1) = Format(Sres(j), "000")
                x = x + 1
            Next
            Range("c" & i + 1).Resize(, UBound(b)) = b
            x = 0
        Next
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Wow!! Thanks to all who contributed to this thread! I appreciate all of the help and guidance!! Thanks you all again!
 
Upvote 0
For a macro approach, my suggestion (assuming max of 9 digits at this stage) would not involve any looping through rows.

Code:
Sub SetsOf3()
  With Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
    .Value = Evaluate(Replace("1&right(rept(0,9)&#,ceiling(len(#),3))", "#", .Offset(, -1).Address))
    .TextToColumns DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 9), Array(1, 2), Array(4, 2), Array(7, 2))
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top