Dim exp As String
Dim temp, tmpExp As String
Dim length As Integer
length = 0
tmpExp = ""
exp = Trim(xlsheet_TandE.cells(i, 8))
For j = 1 To Len(exp)
temp = Mid(exp, j, 1)
'判断是否是中文
If temp Like "[一-龥]" Then
'截取前26个半角字符
If length + 2 > 26 Then
Exit For
Else
length = length + 2
tmpExp = tmpExp & temp
End If
'判断是否是英文、数字、英文半角句号和空格
ElseIf temp Like "[0-9a-zA-Z. ]" Then
'截取前26个半角字符
If length + 1 > 26 Then
Exit For
Else
length = length + 1
tmpExp = tmpExp & temp
End If
End If
Next j
'将截取后的内容设定到"Explaination"中
xlsheet_TandE.cells(i, 8) = tmpExp
本文介绍了一种使用VBA进行字符串截取的方法,特别是针对包含中文和英文字符的情况。通过对字符串长度的精确控制,实现了从Excel单元格中高效提取所需内容的功能。

被折叠的 条评论
为什么被折叠?



