我想使用 Excel VBA 拆分具有多個分隔符的字串。其中一個字串是:
Raw String: Surat/Gujarat-India-East(Asia) Earth.
Intended Result: Surat Gujarat India East Asia Earth.
問題是我們在錄制宏時不能使用多個其他分隔符。
任何幫助將不勝感激。
uj5u.com熱心網友回復:
這是一種易于理解和添加的方法。
它只是將所有分隔符更改為空格,最后洗掉所有雙空格。
把它放到一個MODULE中。
Sub test()
Dim s As String
s = "Surat/Gujarat-India-East(Asia) Earth"
s = Replace(s, "/", " ")
s = Replace(s, "(", " ")
s = Replace(s, ")", " ")
s = Replace(s, " ", " ")
s = Replace(s, "-", " ")
s = Replace(s, " ", " ")
Debug.Print s
' Then if you want to actually split it...
Dim v As Variant
v = Split(s, " ")
End Sub
要將其用作回傳陣列的函式,該陣列也可用于設定范圍:
Function GetTest(s As String)
's = "Surat/Gujarat-India-East(Asia) Earth"
s = Replace(s, "/", " ")
s = Replace(s, "(", " ")
s = Replace(s, ")", " ")
s = Replace(s, " ", " ")
s = Replace(s, "-", " ")
s = Replace(s, " ", " ")
GetTest = Split(s, " ")
End Function
把你的繩子放進Surat/Gujarat-India-East(Asia) Earth去A1
然后在 中B1,鍵入=GetTest(A1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/508008.html
上一篇:VBA:如何提取行數
下一篇:獲取列中第一個不為0的值
