+ Reply to Thread
Results 1 to 7 of 7

Loop for cycling through names of Lists in a UserForm

  1. #1
    Registered User
    Join Date
    08-30-2012
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    83

    Loop for cycling through names of Lists in a UserForm

    Hi,
    This is in connection with a UserForm (although perhaps it can be considered a general problem!)

    I have a number of Lists (named ListA, ListB, ListC etc.) in a Userform. I wish to add something to a list if it meets a condition. I wish to cycle through all of the lists using a loop.

    So if we assume that the thing we are adding is a Variable called theActivity, then the long way would be to type out would be:

    Please Login or Register  to view this content.
    etc.
    I wish to replace the letters (A-F etc.) with a variable, Letters.

    I thought something like this below would work...
    Please Login or Register  to view this content.
    ...but clearly it's not right and needs to be joined first or another approach is required!!

    I would be very grateful if someone could enlighten me as To what approach I should adopt?

    Thanks for reading my question!

    John

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Loop for cycling through names of Lists in a UserForm

    Maybe like this

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Loop for cycling through names of Lists in a UserForm

    Agreed with stnkynts, but I think your Chr will return lower case letters, not the uppercase letters that are in your lists. An easy way to return capital letters, and not have to look up ASCII codes:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    08-30-2012
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    83

    Re: Loop for cycling through names of Lists in a UserForm

    Bang on stnkynts - Thank you! :o)

    Can you possibly explain why I have to use "Controls" in that case
    Please Login or Register  to view this content.
    , but I don't need it if I am just using
    Please Login or Register  to view this content.
    John

  5. #5
    Registered User
    Join Date
    08-30-2012
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    83

    Re: Loop for cycling through names of Lists in a UserForm

    Thanks Walruseggman.

    It worked in spite of not being a capital, but I appreciate the correction - and learning an alternative way!

    I actually meant to write
    Please Login or Register  to view this content.
    which would give me a capital letter too!

  6. #6
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Loop for cycling through names of Lists in a UserForm

    Can you possibly explain why I have to use "Controls" in that case
    The way you had it you were indicating, through the use of quotes, that your parameters were strings. Quotes indicates a string. So you were misidentifying objects and commands as string (ex "Me.List", ".Additem")

    Listbox, Checkbox, CommandButton, etc are all objects on the UserForm. The UserForm has a parameter to access those objects, called Controls. So for the objects on a userform these are comparible:

    ListBox1 = Me.Controls("ListBox1")
    ComboBox1 = Me.Controls("ComboBox1")

    You cannot use the shortened ListBox1 directly with a variable (i.e ListBox & i = doesn't work) but you can with the Controls parameter (Me.Controls("ListBox" & i) = works)

  7. #7
    Registered User
    Join Date
    08-30-2012
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    83

    Re: Loop for cycling through names of Lists in a UserForm

    Clearly and concisely explained - Thank you again stnkynts!

+ 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. Solver Macro Loop is cycling twice when UserForm is displayed (shown)
    By durgee7 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-25-2013, 10:26 AM
  2. Replies: 1
    Last Post: 10-10-2012, 07:09 AM
  3. [SOLVED] Loop through names of buttons on a userform
    By KAPearson in forum Excel Programming / VBA / Macros
    Replies: 29
    Last Post: 06-10-2012, 04:50 PM
  4. Cycling through a list of Names and repeating actions
    By BeefNoodleSoup in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-27-2011, 04:13 AM
  5. Cycling through sheet names in VBA
    By cqxray in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-14-2007, 03:09 AM

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