|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
字典。。。。- Sub ykcbf() '//2024.12.19
- Set fso = CreateObject("scripting.filesystemobject")
- Set d = CreateObject("Scripting.Dictionary")
- Set sh = ThisWorkbook.Sheets("Sheet1")
- Application.ScreenUpdating = False
- yf = Month(Date)
- With Application.FileDialog(msoFileDialogFilePicker)
- .InitialFileName = ThisWorkbook.Path & ""
- .Title = "请选择对应Excel文件"
- .AllowMultiSelect = False
- .Filters.Clear
- .Filters.Add "Excel文件", "*.xls*"
- If .Show Then f = .SelectedItems(1) Else Exit Sub
- End With
- Set wb = Workbooks.Open(f, 0)
- arr = wb.Sheets(1).UsedRange
- wb.Close 0
- For j = 3 To UBound(arr, 2)
- If Val(arr(1, j)) = yf Then jj = j
- Next
- For i = 2 To UBound(arr)
- s = CStr(arr(i, 1))
- d(s) = arr(i, jj)
- Next
- With sh
- r = .Cells(Rows.Count, 1).End(3).Row
- For i = 2 To r
- s = CStr(.Cells(i, 1).Value)
- If d.exists(s) Then
- .Cells(i, 3).Value = d(s)
- Else
- .Cells(i, 3).Value = d(s)
- End If
- Next
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|