0

I am trying to loop through a named range in Excel and set its value equal to another named range that is dynamic in value (called SensitivityResults). How do I get Excel to essentially say:

Range("Scenario1").Value = Range("SensitivityResults").Value

Range("Scenario2").Value = Range("SensitivityResults").Value

Range("Scenario2").Value = Range("SensitivityResults").Value

etc...

My code as follows does not work:

Dim i As Integer
Dim s As Integer

For i = 1 To 20
  For s = 1 To 20 
    Range("Active_Scenaro") = s
    Calculate
    Range("Scenario(i)").Value = Range("SensitivityResults").Value
  Next s
Next i

1 Answer 1

3

You just need to append the counter i as string to your fixed name Scenario:

Range("Scenario" & i).Value = Range("SensitivityResults").Value
Sign up to request clarification or add additional context in comments.

2 Comments

very useful thanks. How do I get both loop values, s and i to update at the same time rather than having it run through all the s's and then updating the i's after?
@Reno not exactly sure about what you mean, but: Try to use only one loop (like i loop only and use Range("Active_Scenaro") = i? If this is not what you want please edit your original question, be more specific and give an example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.