我在使用UserForm CommandButton Sub中执行SolverSolve时遇到问题

时间:2015-12-06 03:30:46

标签: vba

我是VBA的新手,所以如果我使用不正确的术语或者不够详细,我会道歉。我有一个接受输入的UserForm,点击OK后,会出现一个输入框,在解决整数编程问题之前请求一个最终输入。我能够让它工作一次但是当我重新创建代码并运行相同的代码时,它并没有执行SolverSolve。也没有错误或警告。此外,我已经做了dim Valid as Boolean,Budget as String

  Private Sub CEdataok_Click()
Dim Valid As Boolean

  'Input manually entered data into Data spreadsheet
If AI1C.value = "" Or AI2C.value = "" Or AI3C.value = "" Or BI1C.value = "" Or BI2C.value = "" Or BI3C.value = "" Or AI1E.value = "" Or AI2E.value = "" Or AI3E.value = "" Or BI1E.value = "" Or BI2E.value = "" Or BI3E.value = "" Then

    MsgBox ("Some of the fields have been left empty. Please fill in all fields to continue.")
        Exit Sub

Else

Worksheets("Data").Range("B3").value = AI1C.value
Worksheets("Data").Range("B4").value = AI2C.value
Worksheets("Data").Range("B5").value = AI3C.value
Worksheets("Data").Range("B6").value = BI1C.value
Worksheets("Data").Range("B7").value = BI2C.value
Worksheets("Data").Range("B8").value = BI3C.value

Worksheets("Data").Range("C3").value = AI1E.value
Worksheets("Data").Range("C4").value = AI2E.value
Worksheets("Data").Range("C5").value = AI3E.value
Worksheets("Data").Range("C6").value = BI1E.value
Worksheets("Data").Range("C7").value = BI2E.value
Worksheets("Data").Range("C8").value = BI3E.value


ManualDataEntry.Hide
    End If

        While Valid = False
            Budget = InputBox("Please enter the budget (in USD) allowed for this marketing campaign.", "Budget", 7500)
                If IsNumeric(Budget) Then
                    Valid = True
             Else
                 Valid = False
             MsgBox ("Only numbers can be entered here.")
            End If

       Wend
    Worksheets("Data").Range("D18").value = Budget

SolverSolve UserFinish:=True

0 个答案:

没有答案