View Single Post
  #34   Report Post  
Posted to microsoft.public.excel.misc
Dave Gibson Dave Gibson is offline
external usenet poster
 
Posts: 3
Default how do i separate numbers and text in a cell?

The code I posted above is not showing correctly.
As there is no option here to correct the post I am attaching the correct code below.

---------------------------------------------------

Sub GetHours()

Dim r As Integer
Application.ScreenUpdating = False
Application.DisplayAlerts = False

With Columns("A")
..SpecialCells(xlCellTypeBlanks).EntireRow.Delete
..Replace What:=" hr", Replacement:="hr", LookAt:=xlPart
..Replace What:=" uur", Replacement:="hr", LookAt:=xlPart
..Replace What:=" hrs", Replacement:="hr", LookAt:=xlPart
..Replace What:="hrs", Replacement:="hr", LookAt:=xlPart
End With

r = Range("A1").CurrentRegion.Rows.Count

With Range(Range("B1"), Range("B1").Offset(r, 0))
..FormulaR1C1 = _
"=IF(ISERR(FIND(""hr"",RC[-1])),0,MID(RC[-1],FIND(""hr"",RC[-1])-1,1))"
..Select
End With

Selection.Value = Selection.Value
Range("A1").Select

Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com