我有一個很長的宏,它的這一塊不能正常工作。我已經通過Stack Overflow和其他來源進行了檢查,但無法弄清楚問題所在。當我在單獨的宏中運行此代碼時,它似乎可以正常工作,但是當我將它作爲更大的宏的一部分包含時,它意味着它不再有效。最終的結果是我的公式只在第3行,並沒有按照預期填充到底部。這是與此工作表或數據交互的宏的唯一部分。除此之外沒有什麼會導致問題。在我複製+粘貼特殊值的末尾部分是通過凍結數據來減少處理時間。這是有問題的代碼:填充不起作用
Dim ByCustRow As Long
'Populate the By Customer Summary
Workbooks("Master Customer Statement File").Sheets("Scrubbed Data").Range("C3:E" & LastRow).Copy
Workbooks("Master Customer Statement File").Sheets("By Customer Summary").Range("B3").PasteSpecial xlPasteValues
Workbooks("Master Customer Statement File").Sheets("By Customer Summary").Range("B3:D" & LastRow).RemoveDuplicates Columns:=Array(1, 2, 3)
ByCustRow = Workbooks("Master Customer Statement File").Sheets("By Customer Summary").Range("B" & Rows.Count).End(xlUp).Row
Workbooks("Master Customer Statement File").Sheets("By Customer Summary").Range("E3").Formula = "=SUMIFS('Scrubbed Data'!$J:$J,'Scrubbed Data'!$C:$C,B3,'Scrubbed Data'!$I:$I,"">=""&'By Customer Summary'!$C$1)": Range("E3:E" & ByCustRow).FillDown
Workbooks("Master Customer Statement File").Sheets("By Customer Summary").Range("F3").Formula = "=SUMIFS('Scrubbed Data'!$J:$J,'Scrubbed Data'!$C:$C,B3,'Scrubbed Data'!$I:$I,""<""&'By Customer Summary'!$C$1,'Scrubbed Data'!$I:$I,"">=""&'By Customer Summary'!$D$1)": Range("F3:F" & ByCustRow).FillDown
Workbooks("Master Customer Statement File").Sheets("By Customer Summary").Range("G3").Formula = "=SUMIFS('Scrubbed Data'!$J:$J,'Scrubbed Data'!$C:$C,B3,'Scrubbed Data'!$I:$I,""<""&'By Customer Summary'!$D$1,'Scrubbed Data'!$I:$I,"">=""&'By Customer Summary'!$E$1)": Range("G3:G" & ByCustRow).FillDown
Workbooks("Master Customer Statement File").Sheets("By Customer Summary").Range("H3").Formula = "=SUMIFS('Scrubbed Data'!$J:$J,'Scrubbed Data'!$C:$C,B3,'Scrubbed Data'!$I:$I,""<""&'By Customer Summary'!$E$1,'Scrubbed Data'!$I:$I,"">=""&'By Customer Summary'!$F$1)": Range("H3:H" & ByCustRow).FillDown
Workbooks("Master Customer Statement File").Sheets("By Customer Summary").Range("I3").Formula = "=SUMIFS('Scrubbed Data'!$J:$J,'Scrubbed Data'!$C:$C,B3,'Scrubbed Data'!$I:$I,""<""&'By Customer Summary'!$F$1)": Range("I3:I" & ByCustRow).FillDown
Workbooks("Master Customer Statement File").Sheets("By Customer Summary").Range("B3:I" & ByCustRow).Copy
Workbooks("Master Customer Statement File").Sheets("By Customer Summary").Range("B3:I" & ByCustRow).PasteSpecial xlPasteValues
Application.CutCopyMode = False
'End Populate the By Customer Summary
除了使用FillDown的,只是套用公式整個範圍在一次:'工作簿(「主客戶聲明文件」)表(「通過客戶摘要」)範圍(「E3:E」。 &ByCustRow).Formula = ...' –
太棒了!這很好。謝謝你的時間斯科特。 我是新來的,有沒有辦法讓我把問題標記爲回答? –