+ Reply to Thread
Results 1 to 8 of 8

Dates in excel sheet not matching dates in comobox1

  1. #1
    Registered User
    Join Date
    07-25-2017
    Location
    Oiho
    MS-Off Ver
    2010 standard
    Posts
    90

    Dates in excel sheet not matching dates in comobox1

    I hope this is an easy question as I can't post and data due to the fact that it is classified.
    I have a combo box (on a user form) with dates in it and on sheet2 in cell J is same dates. I want to do and if statement.
    If the user picks a date in the combo box it goes through range("J" & i).
    If combobox1.value = sheets(2).range("J" & i) then
    Sheets(2).Range("B" & i).EntireRow.Copy
    Sheets.Add After:=Sheets(Sheets.Count)
    Sheets(3).Paste
    End If
    Next i

    The dates look the same visually but it never gets past the if statement.
    So for whatever reason...it is not recognizing the two dates as the same.
    Thanks for any help.
    Last edited by ColemanJames; 11-09-2017 at 02:06 PM.

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,150

    Re: Dates

    Some dates are in "text" format (combobox) and some in "date" format (sheet) or both date groups have different formatting, e.g.: mm/dd/yyyy vs. m/d/yy or others.

  3. #3
    Registered User
    Join Date
    07-25-2017
    Location
    Oiho
    MS-Off Ver
    2010 standard
    Posts
    90

    Re: Dates

    porucha vevrku ,
    Thanks for the reply.
    I failed to mention that I have both the sheet dates and the combobox1 dates formatted with ("m/d/yyyy")

  4. #4
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,150

    Re: Dates

    What is the dates source for combobox ? This Sheet2 with cells in column 'J' ? Maybe an attachment and all vba code for that For...Next loop ?

  5. #5
    Registered User
    Join Date
    07-25-2017
    Location
    Oiho
    MS-Off Ver
    2010 standard
    Posts
    90

    Re: Dates

    '''''''Populate combo box
    For i = 2 To 200
    If Sheets(2).Range("B" & i) = Customer Then

    combobox1.AddItem Sheets(2).Range("J" & i).Value
    combobox1.Value = Format(combobox1.Value, "m/d/yyyy")

    End If
    Next i

  6. #6
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,150

    Re: Dates

    Your first vba code ... is as below - this is not the whole code, missing the first lines.
    What is there ... "cia top secret" ?
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-25-2017
    Location
    Oiho
    MS-Off Ver
    2010 standard
    Posts
    90

    Re: Dates in excel sheet not matching dates in comobox1

    porucha vevrku ,
    That code Populates the combobox1. the code below is what im trying to do.

    Private Sub cbSearch_Click()
    Sheets(2).Activate

    ActiveCell.Offset(0, 8).Select

    For i = 2 To 10

    If ActiveCell = combobox1.Value Then

    Sheets(2).Range("B" & i).EntireRow.Copy
    Sheets.Add After:=Sheets(Sheets.Count)
    Sheets(3).Paste
    End If
    Next i
    End of Sub

  8. #8
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,150

    Re: Dates in excel sheet not matching dates in comobox1

    1. The values in the ComboBox list are of type "String", so if you are searching some dates, use:
    Please Login or Register  to view this content.
    2. Shorter code to fill the list of 'ComboBox', e.g:
    Please Login or Register  to view this content.
    then in UserForm module:
    Please Login or Register  to view this content.
    3. 'ComboBox1.AddItem' is starting from index = 0.
    So if 'i = 2' then this means that you start calculating from the value of index/list entry = 3
    Last edited by mjr veverka; 11-09-2017 at 05:35 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Populating list of dates from another sheet with Start Dates and End Dates
    By Jesshloly in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-05-2015, 04:07 AM
  2. [SOLVED] Creating a formula to populate range of cells between dates based on start and end dates
    By Rainmain82 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-20-2014, 07:42 PM
  3. Check dates in range either same dates or different dates by formula
    By breadwinner in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-12-2013, 07:42 AM
  4. Replies: 6
    Last Post: 03-11-2013, 06:11 PM
  5. [SOLVED] Array of dates when tested shows no dates ......but there are dates
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-29-2012, 12:45 PM
  6. [SOLVED] Highlight Group of Dates if Dates Match List of other Dates
    By martinpgibson in forum Excel General
    Replies: 5
    Last Post: 10-24-2012, 08:14 PM
  7. [SOLVED] Auto filling dates based on previously entered dates and averaging numbers if dates equal
    By grambograham in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-11-2012, 03:21 PM

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