+ Reply to Thread
Results 1 to 4 of 4

UserForms ListIndex weird issue

  1. #1
    Registered User
    Join Date
    01-19-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2007
    Posts
    26

    UserForms ListIndex weird issue

    ---- ANOTHER EDIT -----

    I'll try to sum up the whole thing to you guys, than maybe someone can help me.

    Although the
    Please Login or Register  to view this content.
    and the
    Please Login or Register  to view this content.
    works on this listbox, depending on which list item I'm trying to select It just won't work.

    Whenever I try to use variables insted of the "1", it won't work, mostly the times or situations.

    If I try to run any operation with the variable it just won't work (Like A UserForm.ListBox.ListCount - 1, wouldn't work)

    Whenever I try to select the last item it won't work


    -----------------------------------

    Hi Guys..

    I'm having this unusual trouble with the listindex property of a listbox on an userform.

    The code below search for a range and refreshes the listbox with the range values.
    Please Login or Register  to view this content.
    The sub routine that I'm fireing in the midle of the code above can be seen here:

    Please Login or Register  to view this content.
    On my form, I got 2 command buttons which I use to change the position of an Item on the predeterminated range and, I fire the listbox refreshing code.

    One of the buttons, sends the selected listindex up and the other one sends it down.

    the "send up" code can be seen here:

    Please Login or Register  to view this content.

    The thing is, as you can see, the LiCache variable, which can be seen in the last line of the code above, is the ListIndex of the selected item after I changed its position up (ex.: ListIndex - 1), and, in the first code I wrapped, I try to keep the previously selected item still selected.

    I have oftenly used this kind of control on my listboxes, but this time IT JUST DOESN'T WORK.

    I have tested it so many times and it even stores the right value in the LiCache variable and also changes the listbox.listindex to the desired value, but it doesn't select the item.

    I hope I made myself clear.

    Thanks for your attention.

    Att. Daniel

    --------- EDIT -----------
    The UserForm can be seen on the attached picture. The two buttons I was Talking about are the /\ and \/ last two.
    Attached Images Attached Images
    Last edited by bagulhodoido; 01-19-2011 at 11:29 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: UserForms ListIndex weird issue

    Attach an example workbook, not a picture
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: UserForms ListIndex weird issue

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by snb; 01-20-2011 at 05:46 AM.



  4. #4
    Registered User
    Join Date
    01-19-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: UserForms ListIndex weird issue

    Quote Originally Posted by royUK View Post
    Attach an example workbook, not a picture
    I can't. It's a worksheet from the company I work for. I could create a similar one, which I did, but in the other worksheet the problem just didn't happened.

    Quote Originally Posted by snb View Post
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    I have tried this routines, but the problem persisted.



    Anyway, I kinda solved it. It had something to do with the .ColumnWidth property.

    I solved it by changing the ColumnWidth to 28 pt;40 pt;40 pt;40 pt;30 pt as the standard width. And removed that line from the routine. After that, It worked fine.

    It's not the brightest solution, but at least it's a solution.

    If anyone knows why this .ColumnWidth property remove the selection from the listbox and won't let me select listbox entries through the routine let me know.

    Thanks for your help guys

    ---- EDIT ----
    Btw, analizing snbs code, Is there anyway to select a determinated Region without selecting the Worksheet it lies in?

    I ask that because I noticed that there are a few actions that make the whole routine slow, like, copying, inserting, formating and changing through worksheets as an example.

    I always avoid using any of those actions because of that. Although, whenever you need to select a range, you must be in the right worksheet.
    Last edited by bagulhodoido; 01-20-2011 at 08:20 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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