Solved

Add time reference

Posted on 2011-09-14
11
295 Views
Last Modified: 2012-05-12
Hi Experts,

I need Expert help. How add-in automatically data at Column A with “:” and “.” E.g 06451800 become 06:45:18.00. Hope Experts could help.

Time.xls
0
Comment
Question by:Cartillo
  • 3
  • 3
  • 3
  • +1
11 Comments
 
LVL 17

Expert Comment

by:andrewssd3
ID: 36534608
Do you want the result to be a real Excel time value, or just a string with the : and . added?
0
 
LVL 17

Expert Comment

by:andrewssd3
ID: 36534848
If so, this formula in Column B will do it:

=TIME(MID(A4,LEN(A4)-7,2),MID(A4,LEN(A4)-5,2),MID(A4,LEN(A4)-3,4)/100)

Open in new window


It does not work with your first value, which you have converted to a number.
0
 
LVL 8

Assisted Solution

by:wchh
wchh earned 50 total points
ID: 36534891
Try the formula below:
=LEFT(A2,2) &":"&MID(A2,3,2)&":"&MID(A2,5,2)&"."&MID(A2,7,2)
0
 
LVL 8

Expert Comment

by:wchh
ID: 36534910
Or for A2, length = 7,
=IF(LEN(A2)=8,LEFT(A2,2) &":"&MID(A2,3,2)&":"&MID(A2,5,2)&"."&MID(A2,7,2),"0" &LEFT(A2,1) &":"&MID(A2,2,2)&":"&MID(A2,4,2)&"."&MID(A2,6,2))
0
 

Author Comment

by:Cartillo
ID: 36535008
Hi,

Is that possible to create a conditional formatting at column A?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 50

Assisted Solution

by:barry houdini
barry houdini earned 100 total points
ID: 36535016
Thuis formula in B2 should do what you need

=TEXT(A2,"00\:00\:00\.00")+0

format B2 as hh:mm:ss.00 and copy down - see attached

What do you need conditional formatting to do?

regards, barry
Time-barry.xls
0
 
LVL 50

Assisted Solution

by:barry houdini
barry houdini earned 100 total points
ID: 36535040
....if you mean you want to input data as shown and for it to automatically convert to a time value - that isn't possible without VBA......unless you "cheat" and use a custom format like this

00":"00":"00"."00

With that if you enter 1234123 then that will display as

01:23:41:23

....but it won't be a valid time value that you can use in calculations

regards, barry
0
 

Author Comment

by:Cartillo
ID: 36535084

Hi Barry,

Sorry to complicate the whole think. Can you help to put this via VBA? When I import the actual data this column will be automatically added with “:” and ‘:”. Hope you will consider this.
0
 
LVL 50

Expert Comment

by:barry houdini
ID: 36535227
VBA isn't my area of expertise - I'll see if anybody else can help you out......

barry
0
 
LVL 17

Accepted Solution

by:
andrewssd3 earned 350 total points
ID: 36535317
For VBA, try this:

Public Sub FixTimes()

    Dim c As Excel.Range
    Dim rngLook As Excel.Range
    Dim strTime As String
    
    ' get the used part of column A, excluding the first row
    Set rngLook = Application.Intersect(Range("A:A"), ActiveSheet.UsedRange)
    Set rngLook = rngLook.Offset(1, 0).Resize(rngLook.Rows.Count - 1, 1)
    
    For Each c In rngLook.Cells
        strTime = c.Value2
        strTime = String(8 - Len(strTime), "0") & strTime
        ' only do eight character fields
        strTime = Mid(strTime, 1, 2) & ":" & _
                    Mid(strTime, 3, 2) & ":" & _
                    Mid(strTime, 5, 2) & "." & _
                    Mid(strTime, 7, 2)
        c.Value2 = strTime
    Next c
    rngLook.NumberFormat = "hh:mm:ss.00"

End Sub

Open in new window

0
 

Author Closing Comment

by:Cartillo
ID: 36536304
Hi andrewssd3,

Cool! thanks a lot for the help.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now