Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6650591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:54:37+00:00 2026-05-26T00:54:37+00:00

I have a black box excel model with 1 sheet. It has 2 inputs,

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:54:38+00:00Added an answer on May 26, 2026 at 12:54 am

    Not sure, but this may be what you’re looking for: just modify the arrays which contain the parameter names and value ranges.

    Sub TestModelInputs()
    
        Dim shtModel As Worksheet, shtResults As Worksheet
        Dim arrNames, arrMin, arrMax, arrStep, arrVals, x
        Dim rw As Long, lb, ub, n, incr As Boolean
    
        '###modify input parameters here
        arrNames = Array("Input1", "Input2", "Input3")
        arrMin = Array(1, 1, 1)
        arrMax = Array(4, 5, 6)
        arrStep = Array(1, 1, 1)
        '###done with parameter setup
    
        Set shtModel = ThisWorkbook.Sheets("Model")
        Set shtResults = ThisWorkbook.Sheets("Results")
    
        rw = 1
        arrVals = arrMin
        lb = LBound(arrNames)
        ub = UBound(arrNames)
        n = (ub - lb) + 1
        shtResults.UsedRange.ClearContents
    
        Do             
            rw = rw + 1
            For x = lb To ub
                shtModel.Range(arrNames(x)).Value = arrVals(x)
            Next x
    
            With shtResults.Rows(rw)
                .Cells(1).Resize(1, n).Value = arrVals
                .Cells(n + 1).Value = shtModel.Range("Output").Value
            End With
    
            For x = lb To ub
                If arrVals(x) < arrMax(x) Then
                    arrVals(x) = arrVals(x) + arrStep(x)
                    Exit For
                Else
                    If x = ub Then
                        Exit Do
                    Else
                        arrVals(x) = arrMin(x)
                    End If
                End If
            Next x
        Loop
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Excel2010 VBA userform that has one comboBox, from which the user
I have a black-box device with a modem attached (which I can send commands
I have a black box of code that contains many threads. There is no
My scenario: I have one color background image JPG. I have one black text
I tried to draw a model with 197 polygons but i have strange black
We have a web application which has been developed over the past 7 months.
I have a 'black box' application that gets a map of values as parameters,
So I have this black box authentication method, handed down to me from the
I have a fiddle here where a black box moves slowly across the screen.
I have a div box (black) that will display a few different product images

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.