|
对分数进行分母通分以后的加减运算。- Function TF(f1, f2, Optional k = 0)
- a1 = Trim(Split(f1, "/")(0)): b1 = Split(f1, "/")(1)
- a2 = Trim(Split(f2, "/")(0)): b2 = Split(f2, "/")(1)
- t1 = b1: t2 = b2
- Do
- If t1 < t2 Then t = t1: t1 = t2: t2 = t
- t1 = t1 Mod t2
- Loop While t1
-
- Select Case k
- Case 0
- TF = " " & a1 * b2 / t2 + a2 * b1 / t2 & "/" & b1 * b2 / t2 '通分+運算
- Case 1
- TF = b2 / t2 '第1項乗数
- Case 2
- TF = b1 / t2 '第2項乗数
- Case 3
- TF = b1 * b2 / t2 'fm=最小公倍数
- Case 4
- TF = t2 '最大公約数
- Case 5
- TF = " " & a1 * b2 / t2 - a2 * b1 / t2 & "/" & b1 * b2 / t2 '通分-運算
- End Select
- End Function
复制代码 还有,对复数单元格内数值进行【最小公倍数】、【最大公约数】计算的自定义函数:- Function LS(Rng As Range, Optional k = 0) '連続範囲最大公約数と最小公倍数
- Dim t&, t1&, t2&, i%, LM, SM
- LM = 1
- For i = 1 To Rng.Cells.Count
- If IsNumeric(Rng.Cells(i)) And Rng.Cells(i) > 0 Then
- If k = 0 Then t1 = LM Else If SM = 0 Then t1 = Rng.Cells(i) Else t1 = SM
- t2 = Rng.Cells(i)
- Do
- If t1 < t2 Then t = t1: t1 = t2: t2 = t
- t1 = t1 Mod t2
- Loop While t1
- LM = LM * Rng.Cells(i) / t2
- SM = t2
- End If
- Next
- If k = 0 Then LS = LM Else LS = SM
- End Function
复制代码 |
|