拆分单元格上加下划线的单词vba

有没有办法使用vba中的拆分function根据带下划线的单词拆分单元格? 如何将分隔符设置为下划线?

d = Trim(cell.Value2) arr = Split(d, " ") 

这是一种方法。 很多error handling的范围在那里,但是这会给你设置正确的方向。

Teste或其他字符在A1加下划线来testing。

 Public Function getArray(rng As Range) Dim arr() Dim lCtr As Long Dim strText As String Dim strDelim As String '/ Create a delim which is qunique, so you dont miss any data. strDelim = "!!_<{>}##" For lCtr = 1 To rng.Characters.Count If rng.Characters(lCtr, 1).Font.Underline = XlUnderlineStyle.xlUnderlineStyleSingle Then '/ Splits exluding the underlined char strText = strText & strDelim '/ Splits including the underlined char 'strText = strText & rng.Characters(lCtr, 1).Text & strDelim Else strText = strText & rng.Characters(lCtr, 1).Text End If Next getArray = Split(strText, strDelim) End Function Sub test() MsgBox getArray(Cells(1, 1))(0) End Sub