|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
字典。。。。- 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
复制代码
|
|