|
各位老师好! 附件为本人本次求助问题,详见附件。根据四位编码求和(四位编码是根据六位编码 左往右取4位)。代码已写完成,但是数据一多,代码执行
就相对较慢。现求助,可否用字典+数组完成?
原始代码如下:
- Sub 晚班报表()
- Application.DisplayAlerts = False
- Application.ScreenUpdating = False
- Dim strPath As String, i As String, j As String, wb As Workbook, wk As Workbook
- Dim a As Long, b As Long, k As Double
- strPath = ThisWorkbook.Path
- strPath = strPath & IIf(Right(strPath, 1) = "", "", "")
- i = Dir(strPath & "报表.xls*")
- j = Dir(strPath & "销售明细.xls*")
- Set wb = Workbooks.Open(strPath & i)
- Set wk = Workbooks.Open(strPath & j)
- For b = 4 To wb.Worksheets(1).Range("B2").CurrentRegion.Rows.Count + 1
- k = 0
- For a = 2 To wk.Worksheets(1).Range("A1").CurrentRegion.Rows.Count
- If Left(wk.Worksheets(1).Cells(a, 5), 4) = wb.Worksheets(1).Cells(b, 2) Then
- k = k + wk.Worksheets(1).Cells(a, 4)
- End If
- Next
- wb.Worksheets(1).Cells(b, 4) = k
- Next
- With wb
- .Save
- .Close
- End With
- wk.Close
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- End Sub
复制代码 请老师们指教,谢谢!
本帖最后由 釜底抽薪 于 2022-3-14 11:52 编辑
报表.zip
(37.77 KB, 下载次数: 12)
|
|