View Single Post
  #33   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?

This bit of VBA should sort you out.

As I don't know where your data resides on your worksheet :
1. Copy your data and paste in cell A1 of a new workbook or worksheet
2. Copy the code below and paste in the VBE
3. Run the macro "GetHours"
4. Your hours should now be in Col B

---------------------------------------------------
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 - 1

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
-------------------------------------------------
Regards

Dave Gibson
Leeds U.K.


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