本帖最後由 freeffly 於 2013-6-19 15:51 編輯
1.公式不同如下如果填滿動作一樣有辦法簡化嗎
2.公式相同不連續填滿的動作一樣能簡化嗎(v7 v14 v16 v18 公式相同)
曾經天真的想用union+array的方式處理
發現不行,不知道有沒有人有好方法簡略下面的代碼- Sub 銷貨公式()
- Application.ScreenUpdating = False
- nC = Sheets("銷貨").Range("A4").End(xlToRight).Offset(, 1).Column
- nR = Sheets("銷貨").Range("A65536").End(xlUp).Row
- nC1 = Sheets("銷貨").Range("A4").End(xlToRight).Offset(, 1).Column - 2
- x = [iv1].End(xlToLeft).Column - 21
-
-
- With Sheets("全部")
- With .Range("V2")
- .FormulaR1C1 = _
- "=GETPIVOTDATA(""本幣銷貨金額"",銷貨!R3C1,""月份"",R1C)"
- .AutoFill .Resize(1, x)
- End With
- With .Range("V9")
- .FormulaR1C1 = _
- "=SUMPRODUCT((銷貨!R5C" & nC & ":R" & nR & "C" & nC & "=""營業課"")*(銷貨!R4C3:R4C" & nC1 & "=R1C),銷貨!R5C3:R" & nR & "C" & nC1 & ")"
- .AutoFill .Resize(1, x)
- End With
-
- With .Range("V4")
- .FormulaR1C1 = "=GETPIVOTDATA(""合計未收帳款"",帳齡!R1C1,""月份"",R1C)"
- .AutoFill .Resize(1, x)
- End With
- With .Range("V7")
- .FormulaR1C1 = "=VLOOKUP(R1C20,單頭資料!C1:C45,45,0)"
- .AutoFill .Resize(1, x)
- End With
-
- With .Range("V14")
- .FormulaR1C1 = "=VLOOKUP(R1C20,單頭資料!C1:C45,45,0)"
- .AutoFill .Resize(1, x)
- End With
-
- With .Range("V16")
- .FormulaR1C1 = "=R[-14]C-R[-7]C"
- .AutoFill .Resize(1, x)
- End With
- With .Range("V18")
- .FormulaR1C1 = "=R[-14]C-R[-7]C"
- .AutoFill .Resize(1, x)
- End With
- With .Range("V21")
- .FormulaR1C1 = "=VLOOKUP(R1C20,單頭資料!C1:C45,45,0)"
- .AutoFill .Resize(1, x)
- End With
- end with
- End Sub
複製代碼 |