+ Reply to Thread
Results 1 to 6 of 6

Set Listbox value to a variable

  1. #1
    Registered User
    Join Date
    11-23-2024
    Location
    South Africa
    MS-Off Ver
    2021
    Posts
    56

    Set Listbox value to a variable

    Hi all,

    I have the following code to set information up in a listbox:

    Please Login or Register  to view this content.
    The occupantsval has a value of 43.

    But the Value = statement fails with "Invalid property value."

    Does anyone know how to correct it, please?

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    31,225

    Re: Set Listbox value to a variable

    Try

    Please Login or Register  to view this content.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Registered User
    Join Date
    11-23-2024
    Location
    South Africa
    MS-Off Ver
    2021
    Posts
    56

    Re: Set Listbox value to a variable

    Hi John,

    Thank you for the feedback but the additem does not work because the code I use gets to run a couple of times and everytime the code gets updated it adds another entry. Is there a way to just set the value, please?

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,530

    Re: Set Listbox value to a variable

    Shouldn't U be Using a TextBox rather then a ListBox?
    Otherwise post an example file and clearly explain what you want to achieve.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  5. #5
    Registered User
    Join Date
    11-23-2024
    Location
    South Africa
    MS-Off Ver
    2021
    Posts
    56

    Re: Set Listbox value to a variable

    Thank you bakerman, just keep it simple. It worked.

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,530

    Re: Set Listbox value to a variable

    Glad to help and thanks for rep+.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

+ 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] Variable listbox for userform
    By sput_sput in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-27-2023, 08:52 AM
  2. [SOLVED] Listbox variable not defined
    By kenjcd in forum Excel General
    Replies: 5
    Last Post: 09-07-2021, 03:35 PM
  3. Trying to assign ListBox to object variable, but getting listbox value
    By JEA_123 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-12-2015, 05:45 AM
  4. [SOLVED] Listbox variable in reference
    By morbdetro in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-24-2014, 05:08 PM
  5. Call ListBox through variable
    By BrianAll in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-25-2013, 07:09 PM
  6. Listbox.value to store as variable?
    By esbenhaugaard in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2012, 01:07 PM
  7. [SOLVED] Setting a listbox using a variable
    By yeahyeahyeah in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-08-2012, 10:19 AM

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