Consulting

Results 1 to 2 of 2

Thread: Listbox Question

  1. #1

    Listbox Question

    Hi All,

    I am making a form that contains a list box. I know how to specify the source but I want to do this:

    I have two columns (A & B). A contains a list of invoice numbers and B contains the year of the invoice. Is it possible to select A as the source for the list box, but only use the cells that have 2009 in column B.

    If that can't be done, what is the VBA code to only copy and paste the cells in A with 2009 in B

    I have used a similar code to send emails to certain address only, but I'm not sure how to edit it for this purpose.

    Thanks,
    Damien

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You need to build the Listbox, bot bind it

    [vba]

    Private Sub Userform_Initialize()

    For Each cell In Range("A2:A20")

    If cell.Offset(0,1).Value = 2009 Then

    ListBox1.AddItem cell.Value
    End If
    Next cell

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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