+ Reply to Thread
Results 1 to 8 of 8

Searching a column of time data in the given format(ex: 12/8/2015 9:30:53 AM) for data pt

  1. #1
    Registered User
    Join Date
    12-15-2015
    Location
    St. Louis, MO
    MS-Off Ver
    2013
    Posts
    9

    Question Searching a column of time data in the given format(ex: 12/8/2015 9:30:53 AM) for data pt

    I have a set of data which is a set of data points that occur at different time stamps. My time/date is in [$-409]m/d/yy h:mm AM/PM;@ format (ez: 12/8/15 9:30:53 AM). I would like users to be prompted to enter a time value such as "9:30". The program would then search the column (column A) for the user entered time. I do not want users to have to enter a time/date in the format ([$-409]m/d/yy h:mm AM/PM;@). I have tried using the FIND function and played around with formatting the data. I am not sure if converting all of the data to strings will work or if I need a totally different approach.

    The function will then select the row containing that time stamp and copy/paste it to another location.

    Any guidance is much appreciated.
    Attached Files Attached Files
    Last edited by acopp24; 12-15-2015 at 11:19 AM. Reason: Adding test file

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Searching a column of time data in the given format(ex: 12/8/2015 9:30:53 AM) for dat

    Hi acopp24 and welcome to ExcelForum,

    To solve your problem you first have to understand how Excel stores dates and times. Dates are stored as whole numbers and Time of day is stored as a fraction of a day when the 'Date' type is used (which stores data the same as type 'Double').
    For example:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Chances are you will never be successful trying to find '9:30:53 AM' as '9:30' entered by the user using the .Find command due to the way Excel stores the data.

    Without seeing your file, my speculation is that the most likely chances of success would be to scan your data one cell at a time and convert each time to a string (e.g. Format(Range("A3"),"h:mm") to see if there is a match to '9:30'.

    I suggest you upload a sample file if additional help is needed.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

    Lewis

  3. #3
    Registered User
    Join Date
    12-15-2015
    Location
    St. Louis, MO
    MS-Off Ver
    2013
    Posts
    9

    Re: Searching a column of time data in the given format(ex: 12/8/2015 9:30:53 AM) for dat

    I added a file with the times and one of the columns of data. The overall application is more complex than this operation so I'm not sure an "After" file will be helpful. Would vlookup be a more successful approach? I was able to loop through the data and convert it to strings, but the find function is still unsuccessful.

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Searching a column of time data in the given format(ex: 12/8/2015 9:30:53 AM) for dat

    Hi,

    Thanks for the rep points.

    See the attached file which contains 3 of many alternatives to match the time:
    a. Brute Force
    b. .Find / .FindNext using a Helper Column (times converted to text)
    c. Index/Match then Brute Force using a Helper Column (times converted to text)

    Complete code follows below in ordinary code module ModSearchDate:
    Please Login or Register  to view this content.
    Lewis
    Attached Files Attached Files

  5. #5
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Searching a column of time data in the given format(ex: 12/8/2015 9:30:53 AM) for dat

    Hi acopp24,

    With the sample file you supplied and the macro below.
    If I type 09:30 in the input box I don't get a match because it defaults to 09:30:00 which is not in your list.
    If I type 09:30:55 it goes to cell A4, which has the same time.
    If I type 09:31 it goes to cell A9 because there is a 09:31:00.

    There may be bugs or something I'm missing but it seems to work fairly well, give it a try.

    Please Login or Register  to view this content.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  6. #6
    Registered User
    Join Date
    12-15-2015
    Location
    St. Louis, MO
    MS-Off Ver
    2013
    Posts
    9

    Re: Searching a column of time data in the given format(ex: 12/8/2015 9:30:53 AM) for dat

    LJMetzger:

    All three of them work. Thank you

    How would I modify the first method to find the first occurence where the entered time matches a time in the column?
    Then I would like to select X (user input) number of rows before and after it and copy the data from all the columns in the selected rows into another worksheet.

    Thanks
    Last edited by acopp24; 12-17-2015 at 02:52 PM.

  7. #7
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Searching a column of time data in the given format(ex: 12/8/2015 9:30:53 AM) for dat

    Hi,

    See the attached file which uses the following code. I added additional cells on the Spreadsheet for:
    a. Number of rows to copy before the first match
    b. Number of rows to copy after the first match
    c. Destination sheet Name

    In ordinary code Module ModFindFirstMatch:
    Please Login or Register  to view this content.
    To see how the code works, I suggest 'Single Stepping' through the code after the Match is found.

    To access Visual Basic (VBA) see:
    http://www.ablebits.com/office-addin...a-macro-excel/
    a. Click on any cell in the Excel Spreadsheet (may not be needed).
    b. ALT-F11 to get to VBA.
    c. CTRL-R to get project explorer (if it isn't already showing).
    d. Double Click on a 'Module Name' in 'Project Explorer' to see code for that module.

    Debugger Secrets:
    a. Press 'F8' to single step (goes into subroutines and functions).
    b. Press SHIFT 'F8' to single step OVER subroutines and functions.
    c. Press CTRL 'F8' to stop at the line where the cursor is.
    d. 'Left Click' the margin to the left of a line to set (or clear) a BREAKPOINT.
    e. Press CTRL 'G' to open the IMMEDIATE WINDOW. 'debug.print' statements send their
    output to the IMMEDIATE WINDOW.
    f. Select View > Locals to see all variables while debugging.
    g. To automatically set a BREAKPOINT at a certain location put in the line:
    'Debug.Assert False'
    h. To conditionally set a BREAKPOINT at a certain location put in lines similar to:
    if i >= 20 and xTV20 > 99.56 then
    Debug.Assert False
    endif
    i. A variable value will be displayed by putting the cursor over the variable name.

    To manually set a breakpoint, see http://www.wiseowl.co.uk/blog/s196/breakpoints.htm

    Please let me know if you need additional help.

    Lewis
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    12-15-2015
    Location
    St. Louis, MO
    MS-Off Ver
    2013
    Posts
    9

    Re: Searching a column of time data in the given format(ex: 12/8/2015 9:30:53 AM) for dat

    LJMetzger,

    Thank you for your help. Your code works well and I was able to adjust it for my specific application. I have some other questions, but I am going to start a new thread as they are not related to the initial question.

+ 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. Data conversion when format 15.10.2015
    By shdwfx in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-15-2015, 10:25 AM
  2. Replies: 2
    Last Post: 09-28-2015, 07:57 PM
  3. [SOLVED] need corrected data format of date & time like " 04-Jul-2015 23:52:41 020
    By arunjyoti.ec in forum Excel General
    Replies: 1
    Last Post: 07-26-2015, 03:42 AM
  4. [SOLVED] Searching data in two columns and returning data from a third column
    By d dubya in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-12-2014, 05:02 PM
  5. [SOLVED] Searching through a column of items that has data and returning the data name.
    By Syntax in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-21-2013, 11:35 PM
  6. Searching data in 1 row, giving back data from column thats left to searched data
    By AmiGoCS in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-29-2012, 05:16 PM
  7. Excel : Convert data in column to limited row (time and date format)
    By hooi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-01-2011, 07:21 PM

Tags for this Thread

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