在Excel中每11位数后添加逗号

时间:2012-11-01 07:37:52

标签: excel excel-vba excel-2007 vba

我想在excel中每11位数后用逗号逗号,我的数据将是这样的。

ODU88131042ODU88131043ODU88131044ODU88131045ODU65110840ODU65110829ODU65110833ODU65110834ODU88131046ODU88131047ODU88131048ODU88131049ODU88131

我想要这样回答

ODU88131046,ODU88131047,ODU88131048,ODU88131049,ODU88131050,ODU88131051,ODU88131052,ODU88131053,ODU88131054,ODU88131055,ODU88131056,ODU88131057,ODU88131058,ODU88131059,ODU88131060,ODU88131061,ODU88131062,ODU88131063,ODU88131064,ODU88131065,ODU88131066,ODU88131067,ODU88131068,ODU88131069,ODU88131070,ODU88131071,ODU88131072,ODU88131073,ODU88131074,ODU88131075,ODU88131076,ODU88131077,ODU88131078,ODU88131079,ODU88131080,ODU88131081,ODU88131082,ODU88131083,ODU88131084,ODU88131085,ODU88131086,ODU88131087,ODU88131088,ODU88131089,ODU88131090,

它是一个修复,我想要非常11位数的逗号和它只在一个单元格中的行,结果也只显示在一个单元格中。请帮帮我..

2 个答案:

答案 0 :(得分:5)

这是使用VBA的方法。选择要插入逗号的单元格并运行宏。

Sub AddCommas()
    Dim s As String
    s = Selection.Value
    Dim x As Long
    x = Len(s) \ 11
    If Len(s) Mod 11 = 0 Then
        x = x - 1
    End If
    Do Until x <= 0
        s = Left(s, x * 11) & "," & Mid(s, x * 11 + 1)
        x = x - 1
    Loop
    Selection.Value = s
End Sub

答案 1 :(得分:0)

=SUBSTITUTE(TRIM(SUBSTITUTE(" "&SUBSTITUTE(TEXT(A1,REPT("00000000000 ",EVEN(LEN(C4)))),"00000000000 ",)," 00000000000 ",))," ",",")