1

我已将这张表制作成具有营养价值的菜单中的食物项目。然后,我得到了另一个表格,其中每个项目都在一行中,每个项目的消耗量在下​​面的行中。然后,我使用 excel 中的求解器工具来优化膳食选择,并对一顿饭的卡路里量设置限制,并对我使用的营养价值进行某些限制。

当我通过求解器工具运行单纯形算法时,发生的是表中消耗量的值变化,以反映在给定约束条件下你应该吃什么。

我想让它变得灵活,以便我可以更改约束并获得不同的结果,但我想要的是一种简单的方法来显示所做的选择。目前我所拥有的是另一个选项卡上的索引匹配表和值,然后我对其应用过滤器并删除所有消耗量为“0”的项目,但是每次运行求解器时都必须这样做。

有什么方法可以拉出非零并显示这些所指的项目,而不必每次都重做过滤器?

4

1 回答 1

1

这是一个简单的例程,我用来在电子表格表格中查找某些内容并将结果发布在同一页面上(很容易更改为发布在另一张工作表上)。希望这有助于或引导您朝着正确的方向前进。(粗鲁但有效)

Private Sub CommandButton3_Click()
    'FIND A VALUE IN THE LIST AND POST RESULTS

Dim myName, myNumber, myComp

  'Clear the results area
With Worksheets("SheetName").Range("H2:J30").ClearContents
End With
x = 2   'The row to start posting results to
y = 0

  'This is the range to search
With Worksheets("SheetName").Range("A1:D300")

   Set found = .Find(What:=y, LookIn:=xlValues,  LookAt:=xlWhole)
      If Not found Is Nothing Then
        firstAddress = found.Address
      Do

        Set ws = Sheets("SheetName")
        myName = ws.Range("A" & found.Row).Value  'Value in column A
        myNumber = ws.Range("B" & found.Row).Value 'Value in column B
        myComp = ws.Range("C" & found.Row).Value   'Value in column C 

               'I use a MsgBox at first for testing, then comment it out  when I know it's working 
               'MsgBox myName & "   " & myNumber & "    " & myComp

                'Post the results to the desired area
                ws.Range("H" & x).Value = myName
                ws.Range("I" & x).Value = myNumber
                ws.Range("J" & x).Value = myComp
            x = x + 1
        Set found = .FindNext(found)
        If found Is Nothing Then
            GoTo DoneFinding
        End If
        Loop While Not found Is Nothing And found.Address <> firstAddress
   End If
DoneFinding:
End With
Range("A2").Select
End Sub
于 2017-07-27T17:01:03.257 回答