- excel批量导入数据在excel文件的第一列是“sd
- 在文件的第一列是“sd-100101-1”等类似的数据,一个文本文件中的数据是“d:\123\sd-100101-1”等类似的数据。想把文本文件中的数据导入到excel中,同时与第一列中的数据匹配。例如,文本中的某一行内容是“ d:\123\sd-100101-2” ,在excel中第一列中有“sd-100101-2”,那么两者进行匹配,将“d:\123\sd-100101-2”放在“sd-100101-2”所在的那一列。
请高手指点,写出详细步骤或代码,感激不尽。
- Sub 按钮1_单击()
mypath = ThisWorkbook.Path & "\": myfile = "abc123.txt"
On Error Resume Next
Open mypath & myfile For Input As #1
stk = Split(StrConv(InputB(LOF(1), #1), vbUnicode), vbCrLf)
Close #1
For i = 0 To UBound(stk)
Set rng = Columns(1).Find(what:=Split(stk(i), "\")(2), lookat:=xlWhole)
If Not rng Is Nothing Then Cells(rng.Row, 2) = stk(i)
Next
End Sub