hello,
I need your ideas xl xperts on this one. I have a UserForm with a find button. My worksheet contains time values. My question is, when I perform a search or find function, the values being returned on my UserForm from the worksheet are in the form of decimal values but not the actual time values as indicated on the worksheet. Why is that so? Anyone knows how to format the time to return time values as actual time values rather than decimal?
Thanks,
Burke
Burke,
If you format a cell with a time as general it will return a value like 0.0520833333333333 which is 01:15. This is because that how excel stores times.
If you times 0.0520833333333333 by 24 and the cell is formatted as general it will return 1.25
See link for more on time
http://www.mvps.org/dmcritchie/excel/datetime.htm
In vba you could use something like
VBA NoobMsgBox Format(Range("A1").Value, "HH:MM")
_________________________________________
![]()
![]()
Credo Elvem ipsum etian vivere
_________________________________________
A message for cross posters
Please remember to wrap code.
Forum Rules
Please add to your signature if you found this link helpful. Excel links !!!
Hello vba noob,
Thanks for your reply. Here the code I was studying with. I got it from one of the threads here: How can I format the time to return as actual time like in my work sheet?
Thanks,Private Sub cmdadminfind_Click() Dim MatchCell As Range Dim strFind, FirstAddress As String 'what to find Dim rSearch As Range 'range to search Dim f As Integer 'Search Range is the ID numbers column Set rSearch = ActiveSheet.Range("A1", Cells(Rows.Count, "A").End(xlUp)) 'ID number to find strFind = TextBox3.Value 'Allways set All the Named Argumnets for the First Search. 'The system "Find" function uses these settings also. With rSearch Set MatchCell = .Find(What:=strFind, _ After:=Cells(1, 1), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlRows, _ SearchDirection:=xlNext, _ MatchCase:=False) If Not MatchCell Is Nothing Then 'found it 'load entry to form TextBox10.Value = MatchCell.Offset(0, 1).Value 'Employee name TextBox4.Value = MatchCell.Offset(0, 5).Value 'Time 1 TextBox5.Value = MatchCell.Offset(0, 6).Value 'Time 2 TextBox6.Value = MatchCell.Offset(0, 8).Value 'Time 3 TextBox7.Value = MatchCell.Offset(0, 9).Value 'Time 4 TextBox8.Value = MatchCell.Offset(0, 11).Value 'Time 5 TextBox9.Value = MatchCell.Offset(0, 12).Value 'Time 6 FirstAddress = MatchCell.Address CurRow = MatchCell.Row 'Check for and count duplicate entries Do f = f + 1 'count number of matching records Set MatchCell = .FindNext(MatchCell) Loop While Not MatchCell Is Nothing And MatchCell.Address <> FirstAddress If f > 1 Then MsgBox "There are " & f & " instances of " & strFind Me.Height = 318 End If Else MsgBox strFind & " not listed" 'search failed End If End With End Sub
Burke
hello,
I was able to format the correct time values.
I changed the code from:
toTextBox4.Value = MatchCell.Offset(0, 5).Value 'Time 1 TextBox5.Value = MatchCell.Offset(0, 6).Value 'Time 2 TextBox6.Value = MatchCell.Offset(0, 8).Value 'Time 3 TextBox7.Value = MatchCell.Offset(0, 9).Value 'Time 4 TextBox8.Value = MatchCell.Offset(0, 11).Value 'Time 5 TextBox9.Value = MatchCell.Offset(0, 12).Value 'Time 6
Thanks for giving me the idea vbanoob...Another solved thread from the xperts.TextBox4.Value = Format(MatchCell.Offset(0, 5).Value, "HH:MM:SS") TextBox5.Value = Format(MatchCell.Offset(0, 6).Value, "HH:MM:SS") TextBox6.Value = Format(MatchCell.Offset(0, 8).Value, "HH:MM:SS") TextBox7.Value = Format(MatchCell.Offset(0, 9).Value, "HH:MM:SS") TextBox8.Value = Format(MatchCell.Offset(0, 11).Value, "HH:MM:SS") TextBox9.Value = Format(MatchCell.Offset(0, 12).Value, "HH:MM:SS")
Thanks,
Burke
Last edited by Burke; 08-06-2008 at 03:09 PM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks