|
本帖最后由 tcmsod 于 2017-7-19 21:48 编辑
需提取txt中 Purchase?order?:?和Customer?Po: 后的字符,以及数字1开头后字符到excel,详见以下描述及附件说明,请高手抽空解答,谢谢。
期待结果(将符合结果分开三列写到excel表中A:C三列)
VV114937_3 | PO99054659-1 | ME73E0227940 | RR242495_0 | PO99027099-1 | 99360 |
实际运行结果(第1列结果没有提取成功,B:C二列提取结果错行)
| PO99054659-1 | | | ME73E0227940 | | PO99027099-1 | | | 99360 |
代码:
Sub test()
Dim ss As String, a%
Open "E:\input\12\po2.txt" For Input As #1
Do While Not EOF(1)
Input #1, ss
ss = Application.Trim(ss)
If ss Like "Purchase?order?:?" & "*" Or ss Like "Customer?Po: " & "*" Or ss Like "1 " & "*" & "USD" Then
a = a + 1
If ss Like "Purchase?order?:?" & "*" Then
Cells(a, 2) = Replace(ss, "Purchase?order?:?", "")
ElseIf ss Like "Customer?Po: " & "*" Then
Cells(a, 3) = Replace(ss, "Customer?Po: ", "")
Else
Cells(a, 1) = Split(ss, " ")(0)
End If
End If
Loop
Close #1
End Sub
- Sub test()
- Dim ss As String, a%, b&
- Open ThisWorkbook.Path & "\po2.txt" For Input As #1
- a = 1
- Do While Not EOF(1)
- Input #1, ss
- ss = Application.Trim(ss)
- If ss Like "Purchase?order?:?" & "*" Then
- Cells(a, 2) = Replace(ss, "Purchase?order?:?", "")
- b = b + 1
- ElseIf ss Like "Customer?Po: " & "*" Then
- Cells(a, 3) = Replace(ss, "Customer?Po: ", "")
- b = b + 1
- ElseIf ss Like "1 " & "*" & "USD" & "*" Then
- Cells(a, 1) = Split(ss, " ")(1)
- b = b + 1
- End If
- If b = 3 Then a = a + 1: b = 0
- Loop
- Close #1
- End Sub
复制代码
|
|