作业帮 > 综合 > 作业

怎么在excel里设置让几个数自动选择几个算出想要的数字?

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/12 02:04:56
怎么在excel里设置让几个数自动选择几个算出想要的数字?
比如1,2,3,4,5,6这6个数字.想要得出和为9.
然后自动选6,3 .或4,5 .或别的组合.
或者不在excel也行,有没有那个工具,软件什么的可以解决.
我的工作需要是在几万,几千但是不多的数字里算出一个想要的.
比如:12312,21432,11231,7534,8985,24661 .算出39078 .
算出最接近的就行了.
要是自己会编宏就不在这里面问了.
1)在工作表sheet1的A1:F1中输入1~6这6个数字
2)在A3中输入9
3)在工作表界面作如下操作:
标题栏->工具->宏->vixual basic编辑器(单击打开)
在打开的vixual basic编辑器窗口作如下操作:
标题栏->视图->工程资源管理器(单击打开)
双击sheet1(注意你的工作表如果是sheet2,就双击sheet2)
右边出现一大片空白区域
将下述代码复制->粘贴进去
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Integer
[iq1:iv1] = "=rand()"
100:
If Cells(1,251) > 0.5 Then Cells(2,1) = "" Else Cells(2,1) = Cells(1,1)
If Cells(1,252) > 0.5 Then Cells(2,2) = "" Else Cells(2,2) = Cells(1,2)
If Cells(1,253) > 0.5 Then Cells(2,3) = "" Else Cells(2,3) = Cells(1,3)
If Cells(1,254) > 0.5 Then Cells(2,4) = "" Else Cells(2,4) = Cells(1,4)
If Cells(1,255) > 0.5 Then Cells(2,5) = "" Else Cells(2,5) = Cells(1,5)
If Cells(1,256) > 0.5 Then Cells(2,6) = "" Else Cells(2,6) = Cells(1,6)
If [A2] + [b2] + [C2] + [D2] + [E2] + [F2] [A3] Then GoTo 100
End Sub
4)任意单击任何单元格,则在第二行中会为你自动显示等于9的和的数字
再问: 要是像我追问的那里面不可能算出准确的数字,想算最接近的有没有方法?~
再答: 你等下,我写看看!
再问: 您老是个人才。弄出来了保证追分。现在出去的。晚上等你好消息!
再答: 你等一下,你要的接近的是接近到什么程度,相差多少算接近?
再问: 一般是算万位数。百千万位一样,十位个位可以不一样。百位相差越少越好。 准备出去的,还有啥问题不。
再答: '我想到解决方案了! '还是像上面一样操作,但代码更改为如下: Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim i As Integer [iq1:iv1] = "=rand()" n = 0 100: n = n + 1 If Cells(1, 251) > 0.5 Then Cells(2, 1) = "" Else Cells(2, 1) = Cells(1, 1) If Cells(1, 252) > 0.5 Then Cells(2, 2) = "" Else Cells(2, 2) = Cells(1, 2) If Cells(1, 253) > 0.5 Then Cells(2, 3) = "" Else Cells(2, 3) = Cells(1, 3) If Cells(1, 254) > 0.5 Then Cells(2, 4) = "" Else Cells(2, 4) = Cells(1, 4) If Cells(1, 255) > 0.5 Then Cells(2, 5) = "" Else Cells(2, 5) = Cells(1, 5) If Cells(1, 256) > 0.5 Then Cells(2, 6) = "" Else Cells(2, 6) = Cells(1, 6) Cells(1000 + n, 1) = Cells(2, 1) Cells(1000 + n, 2) = Cells(2, 2) Cells(1000 + n, 3) = Cells(2, 3) Cells(1000 + n, 4) = Cells(2, 4) Cells(1000 + n, 5) = Cells(2, 5) Cells(1000 + n, 6) = Cells(2, 6) Cells(1000 + n, 7) = "=abs(A3-sum(A" & 1000 + n & ":" & "F" & 1000 + n & "))" If n = 200 Then GoTo 200 If [A2] + [b2] + [C2] + [D2] + [E2] + [F2] [A3] Then GoTo 100 200: Cells(1000, 7) = "=MIN(G1001:G1200)" For i = 1001 To 1200 Step 1 If Cells(i, 7) = Cells(1000, 7) Then Cells(2, 1) = Cells(i, 1) Cells(2, 2) = Cells(i, 2) Cells(2, 3) = Cells(i, 3) Cells(2, 4) = Cells(i, 4) Cells(2, 5) = Cells(i, 5) Cells(2, 6) = Cells(i, 6) Exit For End If Next i End Sub '一定要多多加分的哦! '晚上我不在线,如果还有什么问题明天帮你解决!