我试图拆分一个字符串列表,它在图纸编号之前显示图纸编号。
我曾尝试使用诸如 left 和 trim 之类的公式,然后使用 Application.WorksheetFunction.Find 命令在 VBA 中重写它们,但我无处可去。
Sub GetIssued()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Set objFSO = CreateObject("scripting.FileSystemObject")
r = 14
fle = ThisWorkbook.Sheets("Header Info").Range("D11") & "\"
Set objFolder = objFSO.GetFolder(fle)
With Sheets("TELECOM")
Range("A14", "I305").ClearContents
For Each objFile In objFolder.Files
Cells(r, 9) = objFile.Name
drwnName = Left(TELECOM.Cells(r, "I"),
Application.WorksheetFunction.Find("s", TELECOM.Cells(r, "I")) - 1)
Cells(rw, "B") = drwnName
Cells(rw, 9).ClearContents
rw = rw + 1
Next
End With
End Sub
我只想要“s”之前的字符串,然后检索“s”之后和另一个单元格中“^”之前的数据。
实现这一目标的多种方法:
(1) 提取的字符串长度始终相同
splitstr = Left(.Cells(r, "I").Value,8)
(2) 使用分割功能
此函数根据分隔符将字符串拆分为数组
splitarr = Split(.Cells(r, "I").Value, "s")
splitstr = splitarr(0) 'would return the first split string
(2) 使用 Instr 函数
此函数确定子字符串在字符串中的位置。这可以确定您要提取的字符串的长度
splitlength = Instr(1, .Cells(r, "I").Value, "s") - 1
splitstr = Left(.Cells(r, "I").Value, splitlength)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句