工作簿包含汇总工作表和随机数量的估算工作表。此子表使用手动更新按钮填充汇总工作表。大多数数据位于已知的固定单元格中。一些数据位于估算工作表上的随机行中。我正在使用函数查找这些行。此子表运行缓慢。我确信这是'大锤'方法。我应该先将单元格值写入数组,然后粘贴到摘要表中吗?还是其他更好的方法?
Sub UpdateSummary()
Call ParaOff
Dim i As Integer
Dim j As Integer
Dim x As Integer
Dim name As String
j = 5
Call HideX
Call SortWorksheets
If Not WorksheetExists(wsF) Then
MsgBox "ERROR: Worksheet '" & wsF & "' is missing."
Else
'Sheets(wsF).Activate
Worksheets(wsF).Range("B7:U41").ClearContents
Worksheets(wsF).Range("W7:W41").ClearContents
For i = 1 To Worksheets.Count
If Worksheets(i).name <> wsF And Worksheets(i).name <> wsG And Worksheets(i).name <> wsI And Worksheets(i).name <> wsJ And Worksheets(i).name <> wsK Then
Worksheets(i).Range("S1").Copy 'PROJECT
Worksheets(wsF).Range("B" & j + i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Worksheets(i).Range("J6").Copy 'LOCATION
Worksheets(wsF).Range("C" & j + i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Worksheets(i).Range("Q1").Copy 'DURATION
Worksheets(wsF).Range("D" & j + i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Worksheets(i).Range("M1").Copy 'PROJECT TOTAL
Worksheets(wsF).Range("E" & j + i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Worksheets(i).Range("S10").Copy 'MISC %
Worksheets(wsF).Range("F" & j + i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Worksheets(i).Range("S11").Copy 'MISC $
Worksheets(wsF).Range("G" & j + i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Worksheets(i).Range("N10").Copy 'OTHER %
Worksheets(wsF).Range("H" & j + i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Worksheets(i).Range("N11").Copy 'OTHER $
Worksheets(wsF).Range("I" & j + i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Worksheets(i).Range("P13").Copy 'GC TOTAL
Worksheets(wsF).Range("J" & j + i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Worksheets(i).Range("K11").Copy 'GC %
Worksheets(wsF).Range("K" & j + i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Worksheets(i).Range("L11").Copy 'GC DAY
Worksheets(wsF).Range("L" & j + i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Worksheets(i).Range("M11").Copy 'GC MONTH
Worksheets(wsF).Range("M" & j + i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Worksheets(i).Range("S14").Copy 'PM %
Worksheets(wsF).Range("N" & j + i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Worksheets(i).Range("K14").Copy 'PM HRS
Worksheets(wsF).Range("O" & j + i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Worksheets(i).Range("S16").Copy 'SUPER %
Worksheets(wsF).Range("P" & j + i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Worksheets(i).Range("K16").Copy 'SUPER HRS
Worksheets(wsF).Range("Q" & j + i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Worksheets(i).Range("S18").Copy 'PE %
Worksheets(wsF).Range("R" & j + i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Worksheets(i).Range("K18").Copy 'PE HRS
Worksheets(wsF).Range("S" & j + i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Worksheets(i).Range("Q10").Copy 'CARP HRS
Worksheets(wsF).Range("T" & j + i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
x = fFindRowByCol(Worksheets(i).name, "I", "Div 26*")
Worksheets(i).Range("P" & x).Copy 'DIV 26 $
Worksheets(wsF).Range("U" & j + i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
x = fFindRowByCol(Worksheets(i).name, "I", "Div 32*")
Worksheets(i).Range("P" & x).Copy 'DIV 32 $
Worksheets(wsF).Range("W" & j + i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
Next i
End If
Call ParaOn
Call Happy
End Sub
2条答案
按热度按时间yhived7q1#
摆脱冗长的重复行
...通过使用变量和数据结构(例如数组,字典(集合))...
说明
密码
The Flow
fdbelqdn2#
好吧,但是解决方案,或者答案只是在评论中,没有复选标记作为答案。这里有这么多规则!在这里发布我的问题并获得解决方案是非常有帮助的,也是我学习编码的机会。