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>
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Using vba:

Code:
Sub a1110422a()
Dim c As Range, j As Long
Columns("B:D").NumberFormat = "@"
    For Each c In Range("A2", Cells(Rows.count, "A").End(xlUp))
        j = 0
        For Each x In Split(c.text, ",")
        j = j + 1: c.Offset(, j) = Format(x, "000")
        Next
    Next
End Sub


Excel 2013/2016
ABCD
1
213,065,102013065102
313,165013165
44,051,065004051065
5600600
618,013,092018013092
Sheet1
<p style="width:4.8em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid rgb(187,187,187);border-top:none;text-align: center;background-color: rgb(218,231,245);color: rgb(22,17,32)">Sheet2</p><br /><br />
 
Upvote 0
Number in A2
Please try at B2:D2
=MID(TEXT($A2,REPT(0,CEILING(LEN($A2),3))),COLUMNS($B2:B2)*3-2,3)
 
Upvote 0
A little simpler formula...

=MID(TEXT($A2,"000000000"),3*COLUMNS($B:B)-2,3)

600 need to be on the left, that where I use REPT(0,CEILING(LEN($A2),3)) instead of "000000000"



13065102013065102
13165013165
4051065004051065
600600
18013092018013092

<tbody>
</tbody>
 
Upvote 0
Edit: Ooops, hadn't seen post 5

A little simpler formula...

=MID(TEXT($A2,"000000000"),3*COLUMNS($B:B)-2,3)
Problem is it doesn't do what Bo-Ry's does or what the OP requested. ;)
 
Last edited:
Upvote 0
Another formula option is to use different formula for the 3 columns, keeping the formulas much simpler.
Each formula copied down.

Excel Workbook
ABCD
213065102013065102
313165013165
44051065004051065
5600600
618013092018013092
Sets of 3




If the numbers can be longer than 9 digits & you have the CONCAT function then ..
B2 copied down
C2 copied across and down

Excel Workbook
ABCDEF
256989513065102056989513065102
33003
44051065004051065
5600000000000600000000000
618013092018013092
Sets of 3 (2)
 
Last edited:
Upvote 0
Hi,
I would suggest
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+"
        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) = Formt(Sres(j),"000")
            Next
            Range("c" & i + 1).Resize(, UBound(b)) = b
        Next
    End With
    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Small modi
Just add the colored line
Code:
a = Application.Transpose(Range("b2").Resize(lr))
[COLOR=#ff0000]    Range("c2:e" & lr).Resize(lr).NumberFormat = "000"[/COLOR]
    Application.ScreenUpdating = False
 
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,947
Members
448,534
Latest member
benefuexx

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