Consulting

Results 1 to 6 of 6

Thread: Solved: Listbox starting value - vlookup disappears?

  1. #1
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location

    Solved: Listbox starting value - vlookup disappears?

    Here's a strange one gents, attached is a workbook where i was trying to help another op's at another forum, the request seemed simple enough....."..if i have a list of numbers for a list box and i type a number in to a cell how can i get the listbox to start at the nearest number to the one in the cell?"....so below i created a userform, a list of numbers called "picks" and in B1 was my control number (which i added to the Control Source of the ListBox properties) all works well unless the number does not appear in the list....not to be beaten i thought ok how about a Vlookup with lookup_range set to TRUE i entered this in C1 changed the control source and it worked.....but only the once as the formula was then deleted, i have tried numerous things but must say its beyond me, Why is it deleting the formula from C1?

    Regards,
    Simon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  2. #2
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Use this instead of your coding for the form. Nearest value will be selected in listboxlist. [VBA]Private Sub UserForm_Activate()
    Me.ListBox1.Value = Application.WorksheetFunction.VLookup(Range("B1"), Range("A1:A41"), 1, True)
    End Sub[/VBA]Charlize

  3. #3
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Thanks Charlize, i dont think i would have thought to do that in the Userform Activate. I posted the solution here http://www.excelforum.com/showthread...61#post1765661

    Regards,
    Simon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  4. #4
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Any ideas why the formula was getting deleted after the userform was initialised?

    Regards,
    SImon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  5. #5
    VBAX Contributor moa's Avatar
    Joined
    Nov 2006
    Posts
    177
    Location
    I've had the same problem before and it's related to controlSource, specifically the fact that it's next to useless if you are trying to do something with a formula. It's a two way thing. Control populates cell, cell populates control. This means that the formula calculates and the calculated value in the cell then populates the control on the form, which in turn populates the cell. Bingo, no formula, just the value.
    Glen

  6. #6
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Quote Originally Posted by Glen
    specifically the fact that it's next to useless if you are trying to do something with a formula.
    nice touch by MS don't you think? it had me baffled, i would have thought Control Source would be a constant else how can it be a reference point if it chnaged by the very item that looks to it?

    Anyway thanks for you explanation Glen....and thanks again Charlize!

    Regards,
    Simon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •