你可以使用这个UDF,以提取[...]
括号括起来的字符串:
Function InBrackets(s As String) As String
With CreateObject("VBScript.RegExp")
.Global = True
.MultiLine = True
.Pattern = "\[\w*\]"
Dim x
For Each x In .Execute(s)
InBrackets = InBrackets & Mid(x, 2, Len(x) - 2) & vbLf
Next
End With
End Function
用法:
B2:=InBrackets(A2)
编辑
好了,让你更好的指定目标,与无关括号后,尝试follwing:
Sub InsertAnticipatedResults(sh As Worksheet)
Dim colABC As Long, abc As Range
With sh
colABC = .Rows(1).Find(what:="ABC", lookat:=xlWhole).Column
.Columns(colABC + 1).Insert
.Cells(1, colABC + 1).value = "Results 1 Anticipated"
.Columns(colABC + 2).Insert
.Cells(1, colABC + 2).value = "Results 2 Anticipated"
Set abc = .Range(.Cells(2, colABC), .Cells(.Rows.Count, colABC).End(xlUp))
End With
Dim res1 As String, res2 As String, result1 As String, result2 As String, x
With CreateObject("VBScript.RegExp")
.Global = True
.MultiLine = True
.Pattern = "^\S*\s*\S*\s"
For Each abc In abc.Cells
result1 = "": result2 = ""
For Each x In .Execute(abc.Text)
res2 = Trim(x)
res1 = Trim(Left(res2, Len(res2) - 2))
res2 = Replace(res2, " ", "")
res2 = Replace(res2, vbTab, "")
If Len(result1) > 0 Then result1 = result1 & vbLf: result2 = result2 & vbLf
result1 = result1 & res1
result2 = result2 & res2
Next
abc.Offset(, 1).value = result1
abc.Offset(, 2).value = result2
Next
End With
End Sub
Sub Testing()
InsertAnticipatedResults ActiveSheet
End Sub
请发表您目前有代码麻烦与。 (并删除链接到一个非现场文件 - 问题应该是自包含的,不要依赖于可能在未来打破的链接。) – YowE3K
我同意,但它很难指定多行文本,它只是让专家在精确的Excel表格上工作。 –
@ YowE3K我希望编辑是可以接受的 –