我有下一个问题,我需要比较一个大约127,000行的excel文件和一个大约1' 500,000行的文本文件。文本文件中的每一行都被八个管道划分,在excel中有8列。我需要在文本行中的第五列使用excel文件中的某些列执行VLookUp。
我一直在做的是:
Sub test()
Dim textline As String, rw As Long, lRow As Long, rw1 As Long
Dim sPath As String, text As Variant
rw1 = 1
sPath = "My_path"
With ActiveWorkbook.Sheets("Sheet1")
For rw = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
text = range("A" & rw).Value2
Open sPath For Input As #1
Do Until EOF(1)
Line Input #1, textline
If InStr(textline, CStr(text)) Then
Sheets(2).Cells(rw1, 1) = textline
Sheets(2).range("A" & rw1).TextToColumns Destination:=range("A" & rw1 & ":H" & rw1), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:="|", TrailingMinusNumbers:=True
rw1 = rw1 + 1
Exit Do
End If
Loop
Close #1
Next rw
End With
End Sub
Sub test()
Dim textline As String, rw As Long, lRow As Long, rw1 As Long
Dim sPath As String, text As Variant, sh As String, c As Integer
sh = "Sheet"
c = 1
rw = 1
rw1 = 1
sPath = "My_path"
With ActiveWorkbook.Sheets("Sheet1")
Open sPath For Input As #1
Do Until EOF(1)
Line Input #1, textline
Sheets("Sheet1").range("A" & rw) = textline
Exit Do
End If
rw = rw + 1
Loop
Close #1
End With
With ActiveWorkbook.Sheets(1)
For rw1 = 1 To .Cells(Rows.Count, 1).End(xlUp).Row
Sheets("Sheet1").range("A" & rw1).TextToColumns Destination:=range("A" & rw1 & ":H" & rw1), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:="|", TrailingMinusNumbers:=True
Next rw1
End With
End Sub
Now
问题是这两种方法耗时太长,有没有人知道一个更好的解决方案可以帮助我解决这个问题?
谢谢你的建议
答案 0 :(得分:0)
由于您超出了正常的行限制,因此我建议您使用Get & Transform(适用于Excel 2016)或Power Query(适用于Excel 2010和2013)。重新设置使用Excel。