View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Remove specific text from cell string

Hi Robert,

If the imported values are text values, perhaps try
something like:

'=============
Public Sub Tester()
Dim timeCell As Range
Dim Rng As Range

Set Rng = Selection
For Each timeCell In Rng.Cells
With timeCell
.Value = TimeValue(.Value)
End With
Next timeCell

Rng.NumberFormat = "hh:mm"

End Sub
'<<=============

---
Regards,
Norman


"Robert H" wrote in message
ups.com...
Im trying to run a macro to look at imported time data in a cell,
remove the am/pm designation and convert the time to 24 clock.

For now I will just select the range of data and run the macro...
the imported data is in general format example: "953am"

My though is to run through the column (selection) test each cell
value and if the cell contains the string "pm", remove "pm" and add
1200 to the numeric value.

If the cell contains "am" then just remove am.

just to get findingt he string right I started with:

Sub FixTime()
Dim timeCell As Range

For Each timeCell In Selection
If timeCell.Value = Right("pm", 2) Then
timeCell.Value = timeCell.Replace("pm", "")
End If

Next
End Sub

However, all the cells with "pm" in them get bypassed
any help will be appreciated.

Robert