+ Reply to Thread
Results 1 to 9 of 9

Listbox displaying named range B but Adding named range A to cell

  1. #1
    Registered User
    Join Date
    01-22-2018
    Location
    G
    MS-Off Ver
    2106
    Posts
    5

    Question Listbox displaying named range B but Adding named range A to cell

    Hello,
    I’m searching for a way to display a named range (from column B) in a userform listbox, but add the value from another named range (from column A) to the active cell after the selection. I didn’t find a thread about listboxes that resembles this. Is there any way to achieve this?

    This is my code:
    Please Login or Register  to view this content.
    Last edited by ikkenieikke; 02-02-2018 at 01:32 PM.

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Listbox displaying named range B but Adding named range A to cell

    Why not load both into listbox then, set columnwidth property of column A to zero to hide it. So you can use column index to retrieve value?

    Sample Code below.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Registered User
    Join Date
    01-22-2018
    Location
    G
    MS-Off Ver
    2106
    Posts
    5

    Re: Listbox displaying named range B but Adding named range A to cell

    That's a clever trick, thank you for the quick reply.

    I've noticed an odd behavior of the listbox. After loading RV from the Active Cell value back in the listbox it's giving V (instead of RV) As the selected value. Somehow it only occurs if the last letter is available as a single letter in that list (...also with A instead of LA).


    Could this be some kind of bug?
    Last edited by ikkenieikke; 02-03-2018 at 06:13 AM.

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Listbox displaying named range B but Adding named range A to cell

    Can you upload sample workbook where you are having that issue? I'm unable to replicate it on my end.

  5. #5
    Registered User
    Join Date
    01-22-2018
    Location
    G
    MS-Off Ver
    2106
    Posts
    5

    Re: Listbox displaying named range B but Adding named range A to cell


  6. #6
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Listbox displaying named range B but Adding named range A to cell

    Sorry, but there's all kind of external links in workbook which is broken (i.e. doesn't exist in my environment).
    Most of them are found in Named Ranges.

    And code immediately defaults to "Subscript Out of Range" error. You'll need to fix these named ranges before you upload.

  7. #7
    Registered User
    Join Date
    01-22-2018
    Location
    G
    MS-Off Ver
    2106
    Posts
    5

    Re: Listbox displaying named range B but Adding named range A to cell

    Sorry about that It should be fixed now.

    https://www.excelforum.com/attachmen...1&d=1517851632
    Attached Files Attached Files

  8. #8
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Listbox displaying named range B but Adding named range A to cell

    Ah, I see your issue.

    You are checking for Instr(ActiveCell.Value, .List(i)) > 0.

    So above is checking that...

    .List(i) occurs as part of ActiveCell.Value...

    R, V, & RV all evaluate to being true for the check. And since you don't have Exist For or any other process to stop the loop.... it finds match as i = 1, 3, & 6. And always exit loop at last match (6).

    Instead of using Instr to check. Use ActiveCell.Value = .List(i) for exact match.

  9. #9
    Registered User
    Join Date
    01-22-2018
    Location
    G
    MS-Off Ver
    2106
    Posts
    5

    Re: Listbox displaying named range B but Adding named range A to cell

    Wow, it worked!

    Thank you again for the quick reply.

+ 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] vba excel - listbox a named range based on a value in cell
    By terriertrip in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-16-2017, 03:42 AM
  2. HELP: Adding Named Range to a ActiveX ListBox
    By nori79 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-20-2015, 02:06 AM
  3. [SOLVED] Assign named range to one cell depending on named range in another
    By x65140 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-22-2015, 11:04 AM
  4. [SOLVED] determining if cell is part of named range and what that named range is
    By stnkynts in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-16-2014, 07:56 PM
  5. [SOLVED] Determining if the value of a cell can be a named range, then assigning named ranges after
    By Romulo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-15-2013, 06:05 PM
  6. Adding row to a named range-updating the named range address
    By kjsconv in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-12-2013, 11:22 PM
  7. Replies: 1
    Last Post: 06-03-2006, 10:55 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