close
標題:
EXCEL總和計算方法
發問:
請問各位高手~ 例如:A1:1400, A2:3200, A3:200, A4:320, A5:443, A6:233, A7:504, A8:3100 而我手邊資訊只有總和3720 我要怎麼知道是由哪幾個數字總合而成的? 請問各位excel達人這能夠透過excel得知嗎?
A1儲存格~A8儲存格 分別輸入 1400, 3200, ..... , 3100. B1儲存格輸入 3720 再利用以下 Excel VBA 計算: Sub Linear_Combination() Dim A(8) As Integer Dim C(8) As Byte Columns("D").ClearContents r = 1 For i = 1 To 8 A(i) = Cells(i, 1) Next For i = 1 To 2 ^ 8 - 1 Temp = i T = 0 S = "" For j = 1 To 8 C(j) = Temp Mod 2 T = T + C(j) * A(j) Temp = Int(Temp / 2) Next If T = [B1] Then For j = 1 To 8 If C(j) = 1 Then S = S & " " & A(j) End If Next Cells(r, 4) = S r = r + 1 End If Next End Sub 執行結果只有一組解: 3200 200 320
其他解答:
Sub test() For i = 1 To 8 For j = 1 To 8 For k = 1 To 8 If i <> j And i <> k And j <> k Then If Cells(i, 1) + Cells(j, 1) + Cells(k, 1) = 3720 Then Cells(i, 2) = Cells(i, 1) Cells(j, 2) = Cells(j, 1) Cells(k, 2) = Cells(k, 1) 2015-07-12 21:44:08 補充: End If End If Next k Next j Next i End Sub 註1:合併上述2段程式碼 註2:與Lopez大師結果相同 註3:答案會顯示在B欄 註4:僅供參考6FE1C172E25AFD66
EXCEL總和計算方法
發問:
請問各位高手~ 例如:A1:1400, A2:3200, A3:200, A4:320, A5:443, A6:233, A7:504, A8:3100 而我手邊資訊只有總和3720 我要怎麼知道是由哪幾個數字總合而成的? 請問各位excel達人這能夠透過excel得知嗎?
- 中永和縣市的專業兒童牙醫診所@1@
- 台南區四技和大學 有進修部的學校 哪幾間-@1@
- 尋找短期儲蓄險
- 啥是[膠原蛋白]
- 從台北市搭火車或公車如何到台南市北門社區大學-@1@
- (急)機車停紅線被拖吊
- X-RAY(Scherer方程式)計算粒徑大小nm問題
- 出售公司債券之損益
- 中國共有多少個朝代---
- K850i手機的3.5G上網並沒有高速啊=.=--
此文章來自奇摩知識+如有不便請留言告知
最佳解答:A1儲存格~A8儲存格 分別輸入 1400, 3200, ..... , 3100. B1儲存格輸入 3720 再利用以下 Excel VBA 計算: Sub Linear_Combination() Dim A(8) As Integer Dim C(8) As Byte Columns("D").ClearContents r = 1 For i = 1 To 8 A(i) = Cells(i, 1) Next For i = 1 To 2 ^ 8 - 1 Temp = i T = 0 S = "" For j = 1 To 8 C(j) = Temp Mod 2 T = T + C(j) * A(j) Temp = Int(Temp / 2) Next If T = [B1] Then For j = 1 To 8 If C(j) = 1 Then S = S & " " & A(j) End If Next Cells(r, 4) = S r = r + 1 End If Next End Sub 執行結果只有一組解: 3200 200 320
其他解答:
Sub test() For i = 1 To 8 For j = 1 To 8 For k = 1 To 8 If i <> j And i <> k And j <> k Then If Cells(i, 1) + Cells(j, 1) + Cells(k, 1) = 3720 Then Cells(i, 2) = Cells(i, 1) Cells(j, 2) = Cells(j, 1) Cells(k, 2) = Cells(k, 1) 2015-07-12 21:44:08 補充: End If End If Next k Next j Next i End Sub 註1:合併上述2段程式碼 註2:與Lopez大師結果相同 註3:答案會顯示在B欄 註4:僅供參考6FE1C172E25AFD66
文章標籤
全站熱搜
留言列表