|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 整理数据()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim ar As Variant
Dim d As Object
Dim objStream, strData
Set d = CreateObject("scripting.dictionary")
f = Dir(ThisWorkbook.Path & "\导出.xls*")
If f = "" Then MsgBox "找不到导出文件!": End
Set wb = Workbooks.Open(ThisWorkbook.Path & "\" & f, 0)
With wb.Worksheets(1)
rs = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:a" & rs)
End With
wb.Close False
Dim arr()
ReDim arr(1 To UBound(ar), 1 To 7)
For i = 1 To UBound(ar) Step 5
If Trim(ar(i, 1)) <> "" Then
n = n + 1
arr(n, 1) = n
arr(n, 2) = "集团内"
arr(n, 3) = ar(i + 1, 1)
arr(n, 4) = ar(i, 1)
arr(n, 5) = Split(ar(i + 4, 1), ".")(0)
d(arr(n, 5)) = n
End If
Next i
Set f = Nothing
f = Dir(ThisWorkbook.Path & "\*.txt")
Do While f <> ""
Set objStream = CreateObject("ADODB.Stream")
objStream.Charset = "utf-8"
objStream.Open
objStream.LoadFromFile (ThisWorkbook.Path & "\" & f)
strData = objStream.ReadText()
s = strData
mc = Split(f, ".")(0)
objStream.Close
Set objStream = Nothing
xh = d(mc)
If xh <> "" Then
arr(xh, 5) = s
End If
f = Dir
Loop
rs = Cells(Rows.Count, 7).End(xlUp).Row
If rs > 1 Then Range("f2:l" & rs) = Empty
[f2].Resize(n, UBound(arr, 2)) = arr
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
评分
-
2
查看全部评分
-
|