返回列表 上一主題 發帖

[發問] 找出最少的組合

回復 1# basarasy
試試看
  1. Sub Ex()
  2.     Dim Rng(1 To 2) As Range, E, R As Variant, C As Variant
  3.     With Sheets("eg.1")
  4.         Set Rng(1) = .[D1:G4]
  5.         Set Rng(2) = .[Q2:R4]
  6.     End With
  7.     For Each E In Rng(2).Rows
  8.         R = Application.Match(E.Cells(1, 1), Rng(1).Columns(1), 0)
  9.         C = Application.Match(E.Cells(1, 2), Rng(1).Rows(1), 0)
  10.         If IsNumeric(C) And IsNumeric(R) Then E.Cells(1, 3) = Rng(1).Cells(C, R)
  11.     Next
  12.     With Rng(2)
  13.         .Cells(.Cells.Count).Offset(1, 1) = "=SUM(" & .Columns(.Columns.Count + 1).Address & ")"
  14.     End With
  15. End Sub
複製代碼

TOP

回復 4# basarasy
[ 如何用最少的錢去買所有數量的商品? ]
你的範例中,沒看到金錢??  ,請再詳列範例 讓大家試試看

TOP

        靜思自在 : 站在半路,比走到目標更辛苦。
返回列表 上一主題