View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Trevor Shuttleworth Trevor Shuttleworth is offline
external usenet poster
 
Posts: 1,089
Default string manipulation

Craig

one way:

Function Cleanse(the_cell As Range) As Variant

' use substitute to replace values
' SUBSTITUTE(text,old_text,new_text)

Cleanse = the_cell.Value

Cleanse = Application.WorksheetFunction.Substitute(Cleanse, "P/N", "")
Cleanse = Application.WorksheetFunction.Substitute(Cleanse, "(FINE)", "")
Cleanse = Application.WorksheetFunction.Substitute(Cleanse, "(ALT)", "")
Cleanse = Application.WorksheetFunction.Substitute(Cleanse, "-", "")

End Function


I think you can only do one cell at a time.

Regards

Trevor


"Craig" wrote in message
...
I want to write a function called cleanse(). I want it to
work the way the sqrt() function works, as in you put it
in a cell (such as B1) and it works on whatever cell is
entered as the parameter (such as A1).

This function (if =cleanse(A1) were entered in cell B1,
for instance) would take what is in A1 (maybe a part #
like N-11-4) and take out all specified characters and put
the cleansed part number in B1 (looking like N114).

Can someone please give me some guidance on how this would
be accomplished? Below is what I have so far....it puts 0
in the cell, but does not do what I want...any help would
be appreciated...


Function Cleanse(the_cell)

For Each the_cell In Selection
ActiveCell.Replace What:="P/N", Replacement:="", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False
ActiveCell.Replace What:="(FINE)", Replacement:="",
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False
ActiveCell.Replace What:="(ALT)", Replacement:="",
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False

Next the_cell

End Function