Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default string manipulation

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default string manipulation

Craig,

Approach below is to specifically include characters.

Public Function Cleanse(InVal As String)
Dim i As Long, strTemp As String

For i = 1 To Len(InVal)
Select Case Mid(InVal, i, 1)
Case "A" To "Z", "a" To "z", "0" To "9": strTemp = strTemp &
Mid(InVal, i, 1)
End Select
Next
Cleanse = strTemp
End Function


If you want to specifically exclude chars:
Select Case Mid(InVal, i, 1)
Case "-"
Case Else: strTemp = strTemp & Mid(InVal, i, 1)
End Select


Rob

"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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
string manipulation, pulling out last name from column [email protected] Excel Worksheet Functions 7 May 4th 08 01:45 AM
Text string manipulation... NWO Excel Worksheet Functions 4 August 3rd 07 03:31 AM
String Manipulation within VBA BillCPA Excel Discussion (Misc queries) 2 December 6th 06 05:29 PM
String Manipulation String Manipulation Excel Discussion (Misc queries) 3 November 30th 05 11:51 PM
String Manipulation Ray Batig Excel Programming 3 December 23rd 03 12:31 AM


All times are GMT +1. The time now is 07:59 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"