+ Reply to Thread
Results 1 to 2 of 2

Combobox date value matching

  1. #1
    Registered User
    Join Date
    08-19-2004
    Posts
    22

    Combobox date value matching

    Hi Everybody,
    I have a array as Sheet1.Range("A1 :G50000") which I keep all my data.
    Now I try to extract some data into listbox as between two dates by
    using combo boxes.My comboboxes have date values.Every time I trigger
    command button seems like the data are not correct in the listbox.
    If you can give me a hand here, I will be highly appreciated. Here is
    my code
    Private Sub ComboBox4_Change()
    ComboBox4.Value = Format(ComboBox4.Value, "MMM/YYYY")
    ListBox2.Clear
    End Sub
    Private Sub ComboBox5_Change()
    ComboBox5.Value = Format(ComboBox5.Value, "MMM/YYYY")
    ListBox2.Clear
    End Sub
    Private Sub CommandButton9_Click()
    Dim cell As Range
    ListBox2.Clear
    ListBox2.ColumnCount = 6
    On Error Resume Next
    For Each cell In Sheet2.Range("A2:C500").Columns(2).Cells
    If Format(cell.Value, "MMM/YYYY") >
    Format(ComboBox4.Value, "MMM/YYYY") _
    And Format(cell.Value, "MM/DD/YYYY") <
    Format(ComboBox5.Value, "MM/DD/YYYY") Then
    ListBox2.ColumnCount = 6
    ListBox2.AddItem cell.Offset(0, -1)
    ListBox2.List(ListBox2.ListCount - 1, 1) = _
    Application.WorksheetFunction.VLookup(cell.Offset(0, -1),
    Sheet1.Range("A1:G50000"), 2, 0)
    ListBox2.List(ListBox2.ListCount - 1, 2) = cell.Offset(0,
    2)
    ListBox2.List(ListBox2.ListCount - 1, 3) = _
    Application.WorksheetFunction.SumIf(Sheet2.Range("A2:A50000"),
    cell.Offset(0, -1), Sheet2.Range("C2:C50000"))
    ListBox2.List(ListBox2.ListCount - 1, 4) = cell.Text
    ListBox2.TextColumn = 1
    End If
    Next cell
    End Sub
    Private Sub UserForm_Initialize()
    Dim maxdeg As Variant
    Dim dteDate As Date
    For dteDate = #1/1/2009# To #2/28/2012#
    ComboBox4.AddItem Format(dteDate, "MM/DD/YYYY")
    ComboBox5.AddItem Format(dteDate, "MM/DD/YYYY")
    Next dteDate
    Next
    End Sub

    Thanks in advance
    Baha

    Best Regards,
    Baha

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Combobox date value matching

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

+ 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