每天我都做同样的工作烦死了~要有VB来进行辅助计算就好了~
每天都是自己用计算器无穷次的试。太麻烦了。
不知道哪个高手可以帮帮小弟!谢谢了!
要求1个数比如20038
要求每个数在2500-2510之间
必须是整数倍
比如
就可以分为
20038=2508*4+2502*3+2500*1
如果是特殊的分不开的数6235
就可以分为
6235=2500*2+1235*1
Private Sub Command1_Click()
MsgBox numsp(20038, 2500, 2510)
End Sub
Public Function numsp(Num As Long, lstart As Long, lend As Long) As String
Dim lm As Long
Dim lb As Long
Dim lmm As Long
Dim lmb As Long
Dim strTemp As String
If IsNumeric(Num) = False Then Exit Function
lm = Num Mod lstart
lb = Fix(Num / lstart)
If lm = 0 Then
strTemp = lstart & "*" & lb
ElseIf lm > 0 Then
lmm = lm Mod (lend - lstart)
lmb = Fix(lm / (lend - lstart))
If lmm = 0 Then
If lmb > lb Then
strTemp = lstart & "*" & lb & "+" & lm
Else
strTemp = lend & "*" & lmb
strTemp = strTemp & "+" & lstart & "*" & (lb - lmb)
End If
Else
If lmb < lb Then
strTemp = lend & "*" & lmb
strTemp = strTemp & "+" & (lstart + lmm)
strTemp = strTemp & "+" & lstart & "*" & (lb - lmb - 1)
ElseIf lmb = lb Then
strTemp = lstart & "*" & lb & "+" & lm
End If
End If
End If
numsp = strTemp
End Function
这个答案 还行吧~