+ Reply to Thread
Results 1 to 3 of 3

Looping through different DV scenarios and ending on a certain one

  1. #1
    Registered User
    Join Date
    08-07-2020
    Location
    Houston, TX
    MS-Off Ver
    Office 365 Enterprise
    Posts
    2

    Looping through different DV scenarios and ending on a certain one

    Hi there,

    I'm using the following code to loop through three scenarios in a workbook and paste the output of each on a results page:

    Set rCopy = Worksheets("Returns").Range("C32:D36")
    Set rDest = Worksheets("Macro Output").Range("C3")

    Set dvCell = Worksheets("Assumptions").Range("A1")

    For Each Cell In Split(dvCell.Validation.Formula1, ",")
    dvCell = Trim(Cell)
    Call InterestCalculations
    rDest.Resize(rCopy.Rows.Count, rCopy.Columns.Count).Value = rCopy.Value
    Set rDest = rDest.Offset(, rCopy.Columns.Count)
    Next Cell

    The data validation cell contains three scenarios - 1, 2, and 3. The first scenario represents actual expectations, while the others reflect outperformance and underperformance. The macro works fine, but when I run it, the loop stops while the data validation cell is at 3. Since scenario 1 is the primary output, I'd like for the data validation cell to reset to 1 whenever the macro has finished running. What can I add to the end of this code to make that happen?

    I'm using Excel 2019 on a 64-bit system.

    Thanks in advance!

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,523

    Re: Looping through different DV scenarios and ending on a certain one

    Hi wholesometendies,

    Welcome to the forum!!

    I dare say you haven't declared your variables so by default they end up being variants (this is why Option Explicit is used). To set the data validation the dvCell needs to be a range variable like so:

    Please Login or Register  to view this content.
    Note as per Rule 2 here, you must enclose any code you post in the appropriate tags as I have done. As this is your first post an administrator will do it for you this time.

    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Registered User
    Join Date
    08-07-2020
    Location
    Houston, TX
    MS-Off Ver
    Office 365 Enterprise
    Posts
    2

    Re: Looping through different DV scenarios and ending on a certain one

    Thanks, Robert. I actually had declared my variables but accidentally excluded them from the code snippet I posted! I had this idea that using that last command might mess up the loop so I never even tried it - simple, but effective and seemingly obvious! Thanks for letting me know about the posting rules and thanks again for the quick response - greatly appreciated.

    -WT

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Using IF for three scenarios
    By mrsjayok in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-02-2018, 12:28 AM
  2. Replies: 4
    Last Post: 05-18-2018, 11:00 AM
  3. [SOLVED] Replace all values with "0" ending to the value with "5" ending
    By mgecelov in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-04-2017, 02:39 PM
  4. [SOLVED] Looping macro to run various scenarios through a model returning each answer automatically
    By millwos in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-15-2016, 08:22 PM
  5. Ending a Looping Macro
    By 5150photo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-09-2009, 07:21 PM
  6. Scenarios
    By JosefS in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 PM
  7. Ending Looping Macro
    By cparaske in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-13-2005, 04:27 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1