+ Reply to Thread
Results 1 to 4 of 4

Time format is unchangeable and unsearchable. Why is that?

Hybrid View

  1. #1
    Registered User
    Join Date
    08-23-2014
    Location
    Boston
    MS-Off Ver
    2013
    Posts
    5

    Time format is unchangeable and unsearchable. Why is that?

    Hey guys,

    Wasn't sure if this was a VBA or General question but here it goes.

    I'm writing a macro that selects a time on one sheet and needs to identify the row that time appears on another sheet. Before doing this, the macro changes all time values to hh:mm:ss.0 format on both sheets. The problem is that with the second page that is being searched, the time is never found using search. Take a look: http://imgur.com/3c4ZxyK Note the time that appears in the formula bar is not the right format, even after the format has been changed.

    And it gets weirder, if I select show formulae, I get this: http://imgur.com/ryydvJm which is the fraction of 24 hours that the time corresponds to. I can't change this, even if I change the format this is the formula. If I select Cell"A3".Value I end up with this number. Note I have searched by values and formulae, I have copied and pasted as value. It's like the format I change it to only exists visually. The interesting thing is that if I select a cell and say cell("A3").text I see my time format, but I can't change the cells to their text property or create a new row of them as their text property.

    The weird thing is that this used to work so I fear I may have changed a setting or something. I have run out of people to ask, if anyone knows what's going on here, I'd

  2. #2
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Time format is unchangeable and unsearchable. Why is that?

    The pictures really don't tell us much.

    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
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  3. #3
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Time format is unchangeable and unsearchable. Why is that?

    Dates are really numbers with the time of day expressed as a decimal fraction. For example when I prepared this reply the date and time was 41874.4879059028 which meant 23/08/2014 11:42:35 AM. What you actually see on your worksheet is formatting of the serial number for the date.

    To make it easier to find and replace, you could select the dates and format them as GENERAL which will change them to serial numbers. Then do a find and replace using the serial numbers. Once finished, change the formatting back to what it was before.

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

    Re: Time format is unchangeable and unsearchable. Why is that?

    Hi T12ISC and welcome to ExcelForum as a poster,

    I think your problem is that Excel dates and times quite often do not play nicely with others. You have to understand how Excel stores dates and times. For example Aug 23, 2014 at approximately 11:58 AM is stored as the number 41874.4988649306 (displayed to 10 decimal places)

    The whole number is the number of days since Excel day ZERO.
    The fraction is the fraction of the current day that has elapsed.

    When converting back and forth between time that is readable to humans, and Excel internal numeric format, there are rounding errors which make finding a match very difficult. I have had success by using helper columns that store the time as text. When date/time is stored as a number it is right justified by Excel, and when it is stored as text it is left justified. I have used both straight text and text with an apostrophe (') as the first character.

    See the attached file for a working example:
    Option Explicit
    
    Sub TestFindATime()
    
      Dim r As Range
      Dim ws As Worksheet
      
      Dim myTime As Date
      
      Dim bNeedMore As Boolean
    
      Dim sAddress As String
      Dim sFindString As String
      Dim sFirstAddress As String
      Dim sSheetName As String
      Dim sTime As String
      
      sSheetName = "Sheet1"
      
      'Set the Worksheet object
      Set ws = Sheets(sSheetName)
      
      'Get the value to search for
      sTime = "08:17:43.2"
      
      'Find the first occurence of the string
      Set r = Nothing
      Set r = ws.Columns("A:C").Find(What:=sTime, _
                          After:=ws.Range("A1"), _
                          LookIn:=xlValues, _
                          LookAt:=xlWhole, _
                          SearchOrder:=xlByRows, _
                          SearchDirection:=xlNext, _
                          MatchCase:=False, _
                          SearchFormat:=False)
                          
                          
      If Not r Is Nothing Then
        'Save the found address as the return value as a string
        MsgBox "First occurrence of '" & sTime & "' on '" & sSheetName & "' is in cell '" & r.Address(False, False) & "'."
      Else
        MsgBox "String '" & sTime & "' was NOT FOUND on '" & sSheetName & "'."
      End If
     
      
      sSheetName = "Sheet2"
      
      Sheets(sSheetName).Select
      
      'Set the Worksheet object
      Set ws = Sheets(sSheetName)
      
      'Find the first occurence of the string
      Set r = Nothing
      Set r = ws.Columns("A:C").Find(What:=sTime, _
                          After:=ws.Range("A1"), _
                          LookIn:=xlValues, _
                          LookAt:=xlWhole, _
                          SearchOrder:=xlByRows, _
                          SearchDirection:=xlNext, _
                          MatchCase:=False, _
                          SearchFormat:=False)
      
      If Not r Is Nothing Then
        'Save the found address as the return value as a string
        MsgBox "First occurrence of '" & sTime & "' on '" & sSheetName & "' is in cell '" & r.Address(False, False) & "'."
      Else
        MsgBox "String '" & sTime & "' was NOT FOUND on '" & sSheetName & "'."
      End If
      
      If Not r Is Nothing Then
      
        'Save the found address as the 'First Address'
        'Save the value to be returned
        sFirstAddress = r.Address(False, False)
       
        'Search for additional values
        'If found add them to the array to be returned
        bNeedMore = True
        While bNeedMore
          Set r = ws.Columns("A:C").FindNext(After:=r)
          sAddress = r.Address(False, False)
          If sAddress = sFirstAddress Then
            bNeedMore = False
          Else
            MsgBox "The next occurrence of '" & sTime & "' on '" & sSheetName & "' is in cell '" & r.Address(False, False) & "'."
          End If
        Wend
      End If
      
      Sheets("Sheet1").Select
      
      
      'Clear the object pointers
      Set r = Nothing
      Set ws = Nothing
    
    End Sub
    Lewis
    Attached Files Attached Files

+ 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. Format time from military time to standard time
    By Valencia0307 in forum Excel General
    Replies: 7
    Last Post: 06-01-2014, 11:15 AM
  2. Unchangeable Value of UserName Function
    By MariaMaya in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-24-2013, 06:20 AM
  3. Sheet partially unsearchable, even when converted to PDF.
    By SpreadShite in forum Excel General
    Replies: 6
    Last Post: 12-01-2011, 02:04 PM
  4. Display time in time format instead of decimal format
    By CasualVisitor in forum Excel General
    Replies: 5
    Last Post: 07-03-2009, 06:24 PM
  5. Column(s) Contents - Unchangeable
    By ref.krishna in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-27-2006, 10:50 AM

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