我一直在創建幾個函數,所有這些函數都有很多相同的代碼。有問題的代碼是從Dim Order_Type As Range
降到Set PMethod10 = Sheets("KRONOS").Range("$BK:$BK")
。VBA存儲全球使用代碼
我怎樣才能把它放在一個全局函數或類似的東西,以便只調用該函數,而不是每次都使用整個代碼?
Public Function BANKING1(rev_date As Date) As Variant
Dim Order_Type As Range
Dim Final_Price As Range
Dim PaidAlt As Range
Dim Excl_Rev As Range
Dim PAmount1 As Range
Dim PMethod1 As Range
Dim PAmount2 As Range
Dim PayDate2 As Range
Dim PMethod2 As Range
Dim Vstatus As Range
Dim Team As Range
Application.Volatile (True)
Set Order_Type = Sheets("KRONOS").Range("$D:$D")
Set Final_Price = Sheets("KRONOS").Range("$H:$H")
Set PaidAlt = Sheets("KRONOS").Range("$I:$I")
Set Excl_Rev = Sheets("KRONOS").Range("$K:$K")
Set Vstatus = Sheets("KRONOS").Range("$DL:$DL")
Set Team = Sheets("KRONOS").Range("$DO:$DO")
Set PAmount1 = Sheets("KRONOS").Range("$O:$O")
Set First_PD = Sheets("KRONOS").Range("$Q:$Q")
Set PMethod1 = Sheets("KRONOS").Range("$R:$R")
Set PAmount2 = Sheets("KRONOS").Range("$T:$T")
Set PayDate2 = Sheets("KRONOS").Range("$V:$V")
Set PMethod2 = Sheets("KRONOS").Range("$W:$W")
Set PAmount3 = Sheets("KRONOS").Range("$Y:$Y")
Set PayDate3 = Sheets("KRONOS").Range("$AA:$AA")
Set PMethod3 = Sheets("KRONOS").Range("$AB:$AB")
Set PAmount4 = Sheets("KRONOS").Range("$AD:$AD")
Set PayDate4 = Sheets("KRONOS").Range("$AF:$AF")
Set PMethod4 = Sheets("KRONOS").Range("$AG:$AG")
Set PAmount5 = Sheets("KRONOS").Range("$AI:$AI")
Set PayDate5 = Sheets("KRONOS").Range("$AK:$AK")
Set PMethod5 = Sheets("KRONOS").Range("$AL:$AL")
Set PAmount6 = Sheets("KRONOS").Range("$AN:$AN")
Set PayDate6 = Sheets("KRONOS").Range("$AP:$AP")
Set PMethod6 = Sheets("KRONOS").Range("$AQ:$AQ")
Set PAmount7 = Sheets("KRONOS").Range("$AS:$AS")
Set PayDate7 = Sheets("KRONOS").Range("$AU:$AU")
Set PMethod7 = Sheets("KRONOS").Range("$AV:$AV")
Set PAmount8 = Sheets("KRONOS").Range("$AX:$AX")
Set PayDate8 = Sheets("KRONOS").Range("$AZ:$AZ")
Set PMethod8 = Sheets("KRONOS").Range("$BA:$BA")
Set PAmount9 = Sheets("KRONOS").Range("$BC:$BC")
Set PayDate9 = Sheets("KRONOS").Range("$BE:$BE")
Set PMethod9 = Sheets("KRONOS").Range("$BF:$BF")
Set PAmount10 = Sheets("KRONOS").Range("$BH:$BH")
Set PayDate10 = Sheets("KRONOS").Range("$BJ:$BJ")
Set PMethod10 = Sheets("KRONOS").Range("$BK:$BK")
BANKING1 = Application.WorksheetFunction.SumIfs(_
PAmount1 _
, Team, "<>9" _
, Vstatus, "<>rejected", Vstatus, "<>unverified" _
, Excl_Rev, "<>1" _
, PMethod1, "<>Credit" _
, PMethod1, "<>Amendment" _
, PMethod1, "<>Pre-paid" _
, PMethod1, "<>Write Off" _
, First_PD, rev_date)
End Function
爲什麼當你不調暗它或在代碼中的任何地方使用它時,你有PAmount3?您是否擁有BANKING1功能,BANKING2功能,BANKING3功能等? – 2011-06-14 20:01:33