vba 字符串有几个字符

分类:函数知识网浏览量:3046发布于:2021-06-21 23:38:27

vba 字符串有几个字符

判断是否有|使用INSTR函数,函数的说明如下:InStr 函数示例 本示例使用 InStr 函数来查找某字符串在另一个字符串中首次出现的位置.Dim SearchString, SearchChar,

L=len(“串”)-Len(replace("串","指定字符)) 含L个指定字符.

1楼纯粹在胡说八道,楼主给你代码:在VB中加入一个按钮:Private Sub Command1_Click() Dim ss As String Dim s As Integer Dim a As Integer Dim i As Integer Dim ii As String Dim sum As Integer ss = "1,2,3,4,5" a = Len(ss) For i = 1 To Len(ss) ii = Mid(ss, i, 1) If ii = "," Then sum = sum + 1 End If Next MsgBox CStr(sum) End Sub 祝楼主成功!

用Instr函数判断

replace/mid/len 3个函数结合使用.用excel数组公式也可以做到.代码如下:sub repstr() dim s1 as string, s2 as string s1 = "123456": s2 = "146" for i = 1 to len(s2) s1 = replace(s1, mid(s2, i, 1), "") next debug.print s1end sub

比如取字符串变量S1的第5个字符并赋值给变量S2:s2 = Mid(s1, 5, 1)

dim num1 as integer,num2 as integer dim num3 as integer,num4 as integer,num5 as integer dim i as integer dim s as string s = inputbox("输入字符串:") for i = 1 to

按Alt+F11,在左边选择相应的表,然后把以下代码粘贴上:Private Sub Worksheet_ MsgBox "最后一个“" & fengefu & "”后的字符为" & lastone End If End IfEnd

'问题太空泛了,没说明啊,就当你想统计表中的字数吧sub a() dim num as integer arr=activesheet.usedrange for i=1 to ubound(arr,1) for j=1 to ubound(arr,2) if arr(i,j)<>"" then num=num+len(arr(i,j)) next next msgbox numend sub

楼主,这个应该调用什么api能很快搞定,不过我一般用vba主要处理数据啥的,我大概试了下,用下面的方法也可行的.sub test()dim arr() as string, brr() as stringdim crr()