1、点击【文件】、【选项】。
2、点击【自定义功能区】,将“开发工具”选上,再点击【确定】。
3、点击【开发工具】、【Visual Basic】。
4、在VBE编辑器的菜单栏上面点击【插入】、【模块】。
5、在模块的代码框里边输入以下VBA程序代码,检查无误后按下【F5】键运行程序。Sub Chu_Qian()Dim i1, i2, i3, i4, str1, str2, str3On Error Resume NextSet MySheet1 = ThisWorkbook.Worksheets("Sheet1") '定义工作表Sheet1For i1 = 2 To 1000If MySheet1.Cells(i1, 1) <> "" Then str3 = "" For i2 = 1 To Len(MySheet1.Cells(i1, 1)) str1 = Mid(MySheet1.Cells(i1, 1), i2, 1) '逐一截取每个字符 If IsNumeric(str1) = True Then '判断是否为数字 i4 = i4 + 1 '累计字符个数 str2 = str2 & str1 '字符拼接 i3 = CVar(str2) / 1000 '除以1000 End If If IsNumeric(str1) <> True Or i2 = Len(MySheet1.Cells(i1, 1)) Then If i2 = Len(MySheet1.Cells(i1, 1)) Then '截取的数字是最后一个时,则 str1 = "" End If If i4 < 4 And i2 > 3 Then '对于小于1的数值,前面补0 i3 = "0" & i3 End If i4 = 0 str3 = str3 & i3 & str1 '算式拼接 i3 = "" str2 = "" End If Next MySheet1.Cells(i1, 2) = Chr(39) & str3 '算式拼接结果填入B列单元格 str3 = ""End IfNextEnd Sub
6、回到Sheet1工作表界面,将会看到其运行结果。