假设我在单元格中有以下字符串:
E. Stark,T.Lannister,A.Martell,P Baelish,B.Dondarrion和J. Mormont.整个维斯特洛的裸露水平增加,导致其零星的季节性气候.纳特.PROC.ACA.科学.(2011)3:142-149.
我想从中提取标题.我正在考虑的方法是编写一个脚本,上面写着"从这个字符串中提取文本,但前提是它长度超过50个字符".这样它只返回标题,而不是像"Stark,T"和"Martell,P"这样的东西.我到目前为止的代码是:
Sub TitleTest()
Dim txt As String
Dim Output As String
Dim i As Integer
Dim rng As Range
Dim j As Integer
Dim k As Integer
j = 5
Set rng = Range("A" & j) 'text is in cell A5
txt = rng.Value 'txt is string
i = 1
While j <= 10 'there are five references between A5 and A10
k = InStr(i, txt, ".") - InStr(i, txt, ". ") + 1 'k …Run Code Online (Sandbox Code Playgroud) 我编写了以下脚本来区分范围内的"<"和">"之间的字符.
我有的是:
Dim Rng As Range
Dim i As Long
i = 2
While i <= 20000
Set Rng = Range("B" & i)
If InStr(Rng, "<") = 0 Then
i = i + 1
ElseIf InStr(Rng, "<") > 0 Then
Rng.Offset(0, 1).FormulaR1C1 = "=mid(left(RC[-1],find(" > ",RC[-1])-1),find(" < ",RC[-1])+1,len(RC[-1]))"
i = i + 1
Else: i = i + 1
End If
Wend
End Sub
Run Code Online (Sandbox Code Playgroud)
当我用更简单的东西替换长公式时,这很有效.然而,当我运行它时,我得到了类型不匹配.我有一种感觉,我错过了一些非常简单的事情.有什么建议?
谢谢