+ Reply to Thread
Results 1 to 12 of 12

ListIndex - combobox

  1. #1
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    ListIndex - combobox

    Hello,

    I have Combobox on Userform, in which I have listed days of month. At the end of Userform initialize event, my code ends with :

    Please Login or Register  to view this content.
    This ofcourse sets Listindex back to first day, but I want Listindex to remain where It was last If I close and reopen Userfom. How can I correct that ?

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: ListIndex - combobox

    Quote Originally Posted by Lukael View Post
    Hello,

    I have Combobox on Userform, in which I have listed days of month. At the end of Userform initialize event, my code ends with :

    Please Login or Register  to view this content.
    This ofcourse sets Listindex back to first day, but I want Listindex to remain where It was last If I close and reopen Userfom. How can I correct that ?
    Don't close the userform. Just Hide it and then show it again. The Initialize procedure won't re-run if you show a hidden userform.

    UserForm1.Hide

    UserForm1.Show
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: ListIndex - combobox

    Thanks for suggestion AlphaFrog,

    but Userform1.Hide doesn't update data in my Userform, and that's what I need. I do that with Unload Me from "refresh" Cmdbutton, and that's why Listindex jumps back to where It ends in code, initialize event must re-run.

    I'm trying to get last listindex.value simply because It would look better to stay where It is, after performed update of Userform.
    Last edited by Lukael; 03-15-2014 at 05:03 PM.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: ListIndex - combobox

    Quote Originally Posted by Lukael View Post
    Thanks for suggestion AlphaFrog,

    but Userform1.Hide doesn't update data in my Userform, and that's what I need. I do that with Unload Me from "refresh" Cmdbutton, and that's why Listindex jumps back to where It ends in code, initialize event must re-run.

    I'm trying to get last listindex.value simply because It would look better to stay where It is, after performed update of Userform.
    The code you have to populate the listbox in the initialize procedure could be duplicated in the Refresh command button procedure. No need to unload the userform just to reuse the initialize procedure.

  5. #5
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: ListIndex - combobox

    If you meant that with starting Userform1.hide and ended with Userform.Show, It doesn't work.

    Besides listbox to update, I have checkboxes and textbox too. Copied all code to refresh button and removed Listindex = 0.

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: ListIndex - combobox

    Can you post both your initialize and refresh procedures. I'' show you what I meant. No need to hide and show if all you want to do is repopulate a list box.

  7. #7
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: ListIndex - combobox

    yes sure, here It is

    Initialize :

    Please Login or Register  to view this content.
    Refresh :

    Please Login or Register  to view this content.
    But under combobox_change event I have more code for ticking checkboxes on userform, need that too ?

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: ListIndex - combobox

    But under combobox_change event I have more code for ticking checkboxes on userform, need that too ?
    I don't know.

    My point was to just repopulate the list box from the refresh command button instead of unloading the user form.

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: ListIndex - combobox

    I tried, but I get error.

    Maybe you should check this attached sample Userform, If you have some time ?

    Consider this last last request, I am getting a feeling that this isn't a simple task.

  10. #10
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: ListIndex - combobox

    Even with your example workbook, I don't appreciate what the Refresh button is refreshing.

    Another suggestion is to have a Populate_Listbox procedure that both the Combobox_Change procedure and the Refresh button call as needed.

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: ListIndex - combobox

    hi Alphafrog,

    tried your code but I receive error "invalid use of null". Could you try on my sample and post It back to me ?

  12. #12
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: ListIndex - combobox

    Hi again,

    I managed to get this code working, It needed some minor changes. To populate listbox is really best option for me. Thanks for help !

+ 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] help getting listindex from listbox
    By edjohns in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-24-2012, 01:33 AM
  2. ListIndex with ComboBox
    By Strife in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 11-09-2011, 02:46 PM
  3. Help with ComboBox ListIndex...
    By skonduru in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-19-2011, 12:58 PM
  4. ListIndex problems...
    By LiamPotter in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-24-2009, 11:36 AM
  5. ListBox and ListIndex
    By mtm4300 via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2006, 01:00 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