View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
L. Howard L. Howard is offline
external usenet poster
 
Posts: 852
Default Add to a "number as text"


try:



Sub Add4Min()

Dim LRow As Long

Dim rngC As Range

Dim dblSub As Double



With ActiveSheet

LRow = .Cells(Rows.Count, 1).End(xlUp).Row

For Each rngC In .Range("A1:A" & LRow)

dblSub = TimeValue(Left(rngC, 5))

rngC = Format(dblSub + TimeSerial(0, 4, 0), "hh:mm") _

& " " & Mid(rngC, 7, 99)

Next

End With

End Sub


Regards

Claus B.



Very nice, Claus.

Just to be sure I understand it...

This line pulls the time value out of the string and is Dimmed as Double to accommodate time and dates:
dblSub = TimeValue(Left(rngC, 5))


This formats the time value as hh:mm (where it was text in the cell)
rngC = Format(dblSub + TimeSerial(0, 4, 0), "hh:mm")


And the "+ TimeSerial(0, 4, 0)" adds 0 hours, 4 minutes, 0 seconds to the time value.

And this grabs all the text past the time value. (with a space and up to 99 characters)
& " " & Mid(rngC, 7, 99)

Is that correct?

Howard