I have a “black box” excel model with 1 sheet. It has 2 inputs, which are named ranges “Input1” and “Input2”, and one output, which is a named range “Output”. I wrote a macro to test the sensitivity of this model to variations in it’s inputs, but I was wondering if there was a more elegant way to do this:
Sub LoopMacro()
Dim outrow As Integer
outrow = 1
For i = 1 To 10 Step 0.5
Range("Input1").Value = i
For j = 1 To 10 Step 0.5
Range("Input2").Value = j
Output outrow
outrow = outrow + 1
Next j
Next i
End Sub
Sub Output(outrow As Integer)
Sheets("Output").Cells(outrow, 1) = Range("Input1").Value
Sheets("Output").Cells(outrow, 2) = Range("Input2").Value
Sheets("Output").Cells(outrow, 3) = Range("Output").Value
End Sub
The problem with this macro is that it requires a for loop for each input variable, and would get rather tedious if I had more than a few inputs. I’m trying to figure out if there’s a way to code this such that I can define n inputs (named ranged “Input1”, “Input1”, to “Inputn”), along with their min and max values, and have the macro automatically loop through the relevant values of Input1-Inputn
Not sure, but this may be what you’re looking for: just modify the arrays which contain the parameter names and value ranges.