使用vba實現附件中的公式計算

時間 2022-11-02 17:10:06

1樓:小柯師傅

拋磚引玉下吧,框架我都寫了,那個按鈕的需求沒實現,你要弄的話明確下。「規律」那個表增加了2個欄位,現在公式可以通用了,詳細看附件吧,有問題再跟。。。

'最多銀聯通道種類

private const maxtype = 100

private const firstrow = 2

'計算引數結構

type caculation

typeid as string        '通道種類描述

vendor_coff as double   '髮卡係數

unipay_coff as double   '銀聯絡數

vendor_bound as double  '髮卡上限

unipay_bound as double  '銀聯上限

end type

'所有計算引數結構陣列

dim caculationitem(maxtype) as caculation

'讀取所有公式引數

public function find_calc(sheetname as string) as integer

find_calc = 0

for i = 0 to maxtype - 1

if thisworkbook.sheets(sheetname).cells(i + firstrow, 1).value = "" then

'退出exit for

else

'redim

'通道種類描述

caculationitem(i).typeid = thisworkbook.sheets(sheetname).cells(i + firstrow, 1).value

'髮卡係數

caculationitem(i).vendor_coff = val(thisworkbook.sheets(sheetname).

cells(i + firstrow, 2).value)

'銀聯絡數

caculationitem(i).unipay_coff = val(thisworkbook.sheets(sheetname).

cells(i + firstrow, 3).value)

'髮卡上限

if isnumeric(thisworkbook.sheets(sheetname).cells(i + firstrow, 4).value) = true then

caculationitem(i).vendor_bound = val(thisworkbook.sheets(sheetname).

cells(i + firstrow, 4).value)

else

caculationitem(i).vendor_bound = 0

end if

'銀聯上限

if isnumeric(thisworkbook.sheets(sheetname).cells(i + firstrow, 5).value) = true then

caculationitem(i).unipay_bound = val(thisworkbook.sheets(sheetname).

cells(i + firstrow, 5).value)

else

caculationitem(i).unipay_bound = 0

end if

end if

next i

debug.print find_calc

end function

'髮卡public function getvendor(typeid as string, paymentamount as double)

index = val(typeid)

'是否有上限判斷

if caculationitem(index).vendor_bound = 0 then

getvendor = paymentamount * caculationitem(index).vendor_coff

else

getvendor = caculationitem(index).vendor_bound

end if

end function

'銀聯public function getunipay(typeid as string, paymentamount as double)

index = val(typeid)

'是否有上限判斷

if caculationitem(index).vendor_bound = 0 then

getunipay = paymentamount * caculationitem(index).unipay_coff

else

getunipay = caculationitem(index).unipay_bound

end if

end function

'毛利潤

public function getgross(typeid as integer, paymentamount as double, transcharge as double)

dim vendor as double

dim unipay as double

'是否有上限判斷

if caculationitem(typeid).vendor_bound = 0 then

vendor = paymentamount * caculationitem(typeid).vendor_coff

else

vendor = caculationitem(typeid).vendor_bound

end if

'是否有上限判斷

if caculationitem(typeid).vendor_bound = 0 then

unipay = paymentamount * caculationitem(typeid).unipay_coff

else

unipay = caculationitem(typeid).unipay_bound

end if

'計算毛利潤

getgross = transcharge - vendor - unipay

end function

2樓:匿名使用者

如果計算公式不是很複雜建議使用錄製巨集,這樣比較簡單!負責的話就要用到**!!

使用公式p FS計算壓強時,要特別注意式中的S是指「受力面積

當f一定時,p與s之間成反比例函式,則函式圖象是雙曲線,同時自變數是正數 故選c 對壓強公式p fs的正確理解是 a 壓力f越大,產生的壓強p越大b 受力面積s越大,產生的壓強p越小c 由p f s可知 a 壓力f越大時,受力面積也越大,則產生的壓強p不一定大,故a不正確 b 受力面積s越大,壓力f...

Excel中滿足多條件的計算公式

if最多用七層,多了就不可以了,所以你這個直接用if做那麼多層是不行的 choose if if c2 2,1 if b2 國外 1,3 6,4,if c2 2,1 if b2 國外 1,3 lookup a1,後面三個 需要用lookup a1,相應列的數字替換。如果有行號列號,那就沒這麼麻煩了 ...

如何在EXCEL中輸入這樣的計算公式

假設a列輸入的是你的x值 即1234之類的 那b1輸入 7.1 3 a1 1 下拉填充公式。b列將根據a列的x值計算出你要的 你可以把 x 放在 某一單元格,如 a1 單元格然後把結果放在 另一單元格,如 b3 那麼你就在 b3裡 放你的公式,把公式裡的 x 改為 a1 就是了,當然要輸入 在前面。...