+ Reply to Thread
Results 1 to 4 of 4

Listbox value return from search

  1. #1
    Registered User
    Join Date
    11-30-2005
    Posts
    4

    Listbox value return from search

    I am trying to create a UserForm that will search a spreadsheet and return multiple values to a listbox. For example the program below searchs column E for the Value in textbox1.

    How do I then return the value from column A of the same row to listbox1?
    Thanks,
    M

    Private Sub CommandButton7_Click()
    With Worksheets(1).Range("e:e")
    Set e = .Find(TextBox1, LookIn:=xlValues)
    If Not e Is Nothing Then
    firstAddress = e.Address
    Do
    "Write value from column A in same row to ListBox1"
    Set e = .FindNext(e)
    Loop While Not e Is Nothing And e.Address <> firstAddress
    End If
    End With
    End Sub

  2. #2
    Rowan Drummond
    Guest

    Re: Listbox value return from search

    Assuming CommandButton7 is on the same userform as ListBox1 and TextBox1
    try:

    Private Sub CommandButton7_Click()
    Dim e As Range
    Dim firstAddress As String
    With Worksheets(1).Range("e:e")
    Set e = .Find(Me.TextBox1.Value, LookIn:=xlValues)
    If Not e Is Nothing Then
    firstAddress = e.Address
    Do
    Me.ListBox1.AddItem e.Offset(0, -4).Value
    Set e = .FindNext(e)
    Loop While Not e Is Nothing And e.Address <> firstAddress
    End If
    End With
    End Sub

    Hope this helps
    Rowan

    Mcat wrote:
    > I am trying to create a UserForm that will search a spreadsheet and
    > return multiple values to a listbox. For example the program below
    > searchs column E for the Value in textbox1.
    >
    > How do I then return the value from column A of the same row to
    > listbox1?
    > Thanks,
    > M
    >
    > Private Sub CommandButton7_Click()
    > With Worksheets(1).Range("e:e")
    > Set e = .Find(TextBox1, LookIn:=xlValues)
    > If Not e Is Nothing Then
    > firstAddress = e.Address
    > Do
    > "Write value from column A in same row to ListBox1"
    > Set e = .FindNext(e)
    > Loop While Not e Is Nothing And e.Address <> firstAddress
    > End If
    > End With
    > End Sub
    >
    >


  3. #3
    Registered User
    Join Date
    11-30-2005
    Posts
    4
    B-E-utiful

    Thanks!

  4. #4
    Rowan Drummond
    Guest

    Re: Listbox value return from search

    You're welcome.

    Mcat wrote:
    > B-E-utiful
    >
    > Thanks!
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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