VBA中如何取得单元格字符串的长度

比如A1:5
A2:600215
A3:11

最后希望取得A1,A3的长度,如果取得长度小于等于3,之前加入000

程序运行后A1:000008
A2:600215
A3:000011

希望VBA达人解答

第1个回答  2007-08-05
写一个格式化函数
Public Function FormatValue(ValStr as string) as string
FormatValue = Format(ValStr,"000000")
End Function


A = 110
FormatA = FormatValue(CStr(A))
第2个回答  2007-08-05
Sub cha()
For i = 1 To 3
a = Cells(i, 1).Text
If Len(a) <= 3 Then a = "'000" & a
Cells(i, 1) = a
Next i
End Sub

参考资料:http://club.excelhome.net/

本回答被提问者采纳