我试着阅读了你的代码,但使用了两本阅读你的代码编写的试用工作簿,效果很好。如果你';d张贴你的作业本,看看是什么#039;除此之外,您可能需要考虑以下提示,以大大加快代码速度:
-;激活;方法
-;查找“;“两者都不包括在内”;对于a22=4到15“;和“;对于a21=2到a9“;循环,因为它只取决于;a19“;最外层的循环变量对于上面的内容,我修改了您的代码,如下所示- Option Explicit
- Sub AylikSiparisDene()
- Dim a20 As Variant
- Dim a5, a9, a19, a23, a21, a22, a24 As Integer
- Dim Rng As Range
- Dim Wb01Sh01 As Worksheet, Wb01Sh02 As Worksheet, Wb02Sh01 As Worksheet
- Application.ScreenUpdating = False
- Set Wb01Sh01 = ActiveWorkbook.Sheets(1) 'sheet from where to read "forecast excelini" workbook name
- Set Wb01Sh02 = ActiveWorkbook.Sheets(2) 'working sheet in main workbook
- Wb01Sh02.Range(Cells(3, 9), Cells(32, 20)).ClearContents
- Workbooks.Open Wb01Sh01.Cells(1, 2)
- Set Wb02Sh01 = ActiveWorkbook.Sheets(1) 'forecast excelini
- a5 = 32
- a9 = 41
- '*******************Aylik bazda model siparisi hesaplanmasi
- For a19 = 3 To a5 'program excelinde model ismi iceren sutunun son dolu satir numarasi
- With Wb01Sh02
- a20 = .Cells(a19, 1) 'aranacak model ismi
- Set Rng = .Range("h:h").Find(what:=a20, lookat:=xlWhole, LookIn:=xlValues)
- End With
- a24 = Rng.Row
- a23 = 0 'aylik siparis adedi sifirlandi
- For a21 = 2 To a9 'forecast te model isminin oldugu satirlar
- With Wb02Sh01
- If .Cells(a21, 1) = a20 Then
- For a22 = 4 To 15
- a23 = .Cells(a21, a22) 'model basina her ayin siparis adedi
- Wb01Sh02.Cells(a24, a22 + 5) = Wb01Sh02.Cells(a24, a22 + 5) + a23
- Next a22
- Else: End If
- End With
- Next a21
- Next a19
- '************************************************************
- Wb01Sh02.Activate
- Application.ScreenUpdating = True
- End Sub
在这里,我使用工作表变量来避免;激活;方法调用并使代码更具可读性(当然,您可以根据需要更改sheets变量名。) |