我在A2单元格中有这个文字:
2018 / Erbe / France / Beflubu,zolin,Benflu,sate,furon,Bensu / 仅显示: VARIABLE /价值($ m):169.46
我试图仅将 VARIABLE 的值复制到单元格D2中。
此单元格中的所有内容都有所不同,唯一固定的内容是"Show Only:"
,"Value ($):"
,所有/
个字符和.
(在值的数字部分) )
我想在VBA中做到这一点。
答案 0 :(得分:1)
尝试下面的代码,代码注释中的解释:
Option Explicit
Sub ExtractAfterShowOnly()
Dim WordsArr() As String
Dim i As Long
Dim MatchString As String
' use Split to read each section between "/" as arra element
WordsArr = Split(Range("A2").Value2, " / ")
' loop through array
For i = 1 To UBound(WordsArr)
' if there's a match, get the text inside and exit the loop
If WordsArr(i) Like "*Show only:*" Then
MatchString = WordsArr(i)
Exit For
End If
Next i
' Use Mid function to show the string after "Show only:"
MsgBox Mid(MatchString, Len("Show only:") + 1)
End Sub