[Solved] Prepare Macros which add comma after every 10 digit in a column [closed]


Please try this, it should work for you,

Sub AddCommas()
Dim s As String
Dim i As Long
Dim j As Long
For k = 1 To 20
For i = 1 To Rows.Count
    s = ""
    If Not IsEmpty(Cells(i, k).Value) And Int(Len(Cells(i, k)) / 10) >= 1 Then
        For j = 1 To Int(Len(Cells(i, k).Value) / 10) + 1
            If j = 1 Then
                s = s & Left(Cells(i, k).Value, j * 10) & ","
            Else
            If j = (Int(Len(Cells(i, k).Value) / 10) + 1) Or (Len(Cells(i, k).Value) / 10) = j Then
                s = s & Mid(Cells(i, k).Value, ((j - 1) * 10) + 1, 10)
            Else
                s = s & Mid(Cells(i, k).Value, ((j - 1) * 10) + 1, 10) & ","
            End If
            End If
        Next j
        Cells(i, k).Value = s
    End If
Next i
Next k
End Sub

Adjust the k variable and i variable as per your starting row position and number of columns. Hope this helps.

15

solved Prepare Macros which add comma after every 10 digit in a column [closed]