|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Option Explicit
Sub TEST7()
Dim ar, br, i&, j&, r&, dic As Object, t#
Dim strFileName$, strPath$, wks As Worksheet, iPosCol&
strPath = ThisWorkbook.Path & "\"
strFileName = strPath & "报价.xlsx"
If Dir(strFileName) = "" Then MsgBox "报价文件不存在,请检查!", vbExclamation: Exit Sub
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
t = Timer
With [A3].CurrentRegion
.Offset(1).Clear
ar = .Resize(10 ^ 3)
r = 1
For j = 1 To UBound(ar, 2)
dic(ar(1, j)) = j
Next j
End With
With GetObject(strFileName)
For Each wks In .Worksheets
br = wks.[A1].CurrentRegion.Value
For i = 3 To UBound(br)
r = r + 1
For j = 1 To UBound(br, 2)
If dic.exists(br(2, j)) Then
iPosCol = dic(br(2, j))
ar(r, iPosCol) = br(i, j)
End If
Next j
Next i
Next
End With
With [A3].Resize(r, UBound(ar, 2))
.Value = ar
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Borders.LineStyle = xlContinuous
.Rows(1).Font.Bold = True
.EntireColumn.AutoFit
.EntireRow.AutoFit
End With
Set dic = Nothing
Application.ScreenUpdating = True
MsgBox "执行完毕!_用时: " & Format(Timer - t, "0.00") & " 秒", 64
End Sub
|
评分
-
2
查看全部评分
-
|