Sub test1()
p = 5 'The position of nth "_"
tx = Cells(1, 1)
For i = 1 To Len(tx)
If Mid(tx, i, 1) = "_" Then jo = jo & " " & i
Next i
s = Split(Mid(jo, 2))
Ans = s(p - 1)
MsgBox "The position of " & p & "th ""_"" is " & Ans
End Sub作者: mlbolerud 時間: 2019-10-21 12:10
感謝兩位大大的解答, 我後來找了一下資料
我想到下面這個方式也可以算出來
Sub test()
Dim no As Byte
Dim Data As String
Data=Cells(3,32).Value ''''' 字串位置
no=Cells(5,32).Value ''''' 要找第幾個 _
Count=0
data_split = Split(Data , "_")
For i=1 To no
Count = Count+1+Len(data_split(i-1))
Next i
MsgBox("第" & no & "個_的位置是" & Count)
EndSub作者: 准提部林 時間: 2019-10-26 12:08
Sub TEST_01()
Dim T$, TR, V%
T = "TouchTest_check_20180630_104354_108F02_68HR-R_K8"
V = 5
TR = Split(T, "_")
If V <= 0 Or UBound(TR) < V - 1 Then MsgBox "超過取字範圍!!": Exit Sub
MsgBox TR(V - 1)
End Sub