|
楼主 |
发表于 2023-2-19 21:33
|
显示全部楼层
您好,您发的这个代码我复制粘贴进去,运行提示错误450- Sub HzWb_COUNT()
- t = Timer
- Application.ScreenUpdating = False
- Set d = CreateObject("scripting.dictionary")
- Dim mpath As String, l_r As Long, n As Long
- Dim rng As Range
- Dim F As String, sht As Worksheet, wb As Workbook
- mpath = ThisWorkbook.Path & ""
- F = Dir(mpath & "*.xlsx") ' 这是要汇总的工作簿文件的扩展名,只有扩展名为“xlsx”的工作簿中的记录才会被汇总。
- Do While F <> ""
- Set wb = Workbooks.Open(mpath & F)
- l_r = Sheets(1).Cells(Rows.Count, 1).End(3).Row - 4
- ar = Sheets(1).Cells(l_r, 2).Resize(5, 1)
- a = Split(Split(F, ".")(0), "年")(0)
- b = Split(Split(Split(F, ".")(0), "年")(1), "月")(0)
- c = Split(Split(Split(Split(F, ".")(0), "年")(1), "月")(1), "日")(0)
- d(F) = Array(Application.Transpose(ar), DateSerial(Val(a), Val(b), Val(c)))
- wb.Close False
- F = Dir '用Dir函数取得其他文件名,并赋给变量
- Loop
- With ActiveSheet
- .UsedRange.Offset(1).ClearContents '清除汇总表中原有的数据, 只保留表头
- For Each Key In d.keys
- Set rng = .Cells(Rows.Count, 1).End(3).Offset(1, 0)
- rng.Value = "降雨量"
- rng.Offset(0, 2).Resize(1, 5) = Application.Transpose(Application.Transpose(d(Key)(0)))
- rng.Offset(0, 1) = d(Key)(1)
- Next
- With .Range(.Cells(2, 1), .Cells(Rows.Count, 1).End(3).Offset(0, 6))
- .Font.Size = 10
- .Borders.LineStyle = 1
- End With
- End With
- ActiveSheet.Range(ActiveSheet.Cells(2, 1), ActiveSheet.Cells(Rows.Count, 1).End(3).Offset(0, 6)).Sort keyl:=ActiveSheet
- Application.ScreenUpdating = True
- MsgBox "汇总完毕,共计耗时:" & Format(Timer - t, "0.0000") & "秒"
- End Sub
复制代码
|
-
运行时错误450错误的参数号或无效的属性赋值
|