[英]Import Big Data from a text file to Excel
我有下一个问题,我需要将一个大约127,000行的excel文件与一个大约1'500,000行的文本文件进行比较。 文本文件中的每一行都被8个管道分隔,在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
问题是这两种方法花费的时间太长了,有人知道更好的解决方案可以帮助我吗?
谢谢你的建议
由于您超出了正常的行数限制,如果您设置使用Excel,建议您使用Get&Transform (对于Excel 2016)或Power Query (对于Excel 2010和2013)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.