+ Reply to Thread
Results 1 to 5 of 5

[Formula] Alternate between two value sets

  1. #1
    Registered User
    Join Date
    11-09-2012
    Location
    seattle
    MS-Off Ver
    Excel 2007
    Posts
    42

    Question [Formula] Alternate between two value sets

    MOD: Can you please move this to the VBA Q/A section. Sorry, wrong section.

    Good morning,

    I have a userform with one textbox and one button. When I click the button I would like the show a name in the textbox.

    The names will alternate between two list of names. One list will have one name, and the other two names.
    However, List B will alternate independently.
    Ideally I would like to see Frank and Bill alternate, while Jon alternates between them. So lets say that I click the button 8 times, it should show Jon 4 times (50%), and Frank and Bill 2 times(25% each).

    Example:

    List A:
    Jon

    List B:
    Frank
    Bill

    Trying to google help on this one is difficult haha
    Last edited by synergeticink; 01-04-2018 at 04:29 PM.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: [Formula] Alternate between two value sets

    Use a public counter and increment it each time you need a new value:

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    11-09-2012
    Location
    seattle
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: [Formula] Alternate between two value sets

    Does this timer run independently in saved memory? I'm not familiar with public counters. Rather then "MsgBox strName" i'm assuming I could use the following code to input the new name, or something to that extent?

    UserForm1.TextBox1.Text = strName

    If it does keep it in memory, would excel keep track of that counter even if I save and close the document and reopen? Trying to think of situations in which it might not work. #thinkingahead
    Last edited by synergeticink; 01-04-2018 at 05:14 PM.

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: [Formula] Alternate between two value sets

    There is no timer - the code runs whenever you use code to run it - like a commandbutton click event. The counter does not retain its value when the file is closed: you could write the value to a cell and read it from there every time it is changed, if that is important.

    And yes, you would use code like

    UserForm1.TextBox1.Text = strName

    in place of the message box.

  5. #5
    Registered User
    Join Date
    11-09-2012
    Location
    seattle
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: [Formula] Alternate between two value sets

    Awesome! Worked perfectly. Thank you!

+ 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] Formula to alternate two values between rooms
    By Ricker090 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-11-2017, 06:11 PM
  2. [SOLVED] Is there any Alternate formula for Sumproduct function?
    By pramoth.u in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 05-29-2017, 05:26 AM
  3. [SOLVED] Alternate to Max Formula
    By Masa1989 in forum Excel General
    Replies: 3
    Last Post: 03-27-2017, 09:01 AM
  4. Formula to count cells with dates based on criteria
    By suneeshpillai in forum Excel General
    Replies: 1
    Last Post: 03-17-2017, 08:21 AM
  5. [SOLVED] Alternate formula for VLOOKUP in reporting.
    By luccallens in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-05-2013, 12:38 PM
  6. Formula: Alternate cell values
    By ugsquish in forum Excel General
    Replies: 2
    Last Post: 09-09-2011, 04:41 PM
  7. Alternate Vlookup formula
    By mangesh in forum Excel General
    Replies: 3
    Last Post: 07-23-2010, 02:40 PM

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