Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default VBA Code -- Cleaning Data

I have some code that is supposed to clean data in a
particular cell. The data is part numbers. Example...

A1 B1
P/N 1234-5 P/N 12345

When you enter the function cleanse(A1) in B1, the cleaned
part number will appear. It took out the dash. There are
other characters I want to do this with. Here is the code
I have....some of it may be right or wrong. If someone
could point me in the right direction on this code, I
would very much appreciate it...

Sub cleanse()

Dim loc As range
Dim block As range

Set loc = ActiveCell
loc.Select

Set block = Selection

For Each Item 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

Next Item

End Sub




thanks for any help...

Craig

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default VBA Code -- Cleaning Data

You can adapt this function by Leo Heuser to remove any characters
that you want. Just change what's inside the array.

Function ReplaceIllegalChars(Filename As String) As String
'' Replaces illegal filename characters with a space.

, 5. August 2001
Dim Illegal As Variant
Dim Counter As Integer

Illegal = Array("<", "", "?", "[", "]", ":", "|", "*", "/")

For Counter = LBound(Illegal) To UBound(Illegal)
Do While InStr(Filename, Illegal(Counter))
Mid(Filename, InStr(Filename, Illegal(Counter)), 1) = " "
Loop
Next Counter

ReplaceIllegalChars = Filename

End Function

HTH
Paul
--------------------------------------------------------------------------------------------------------------
Be advised to back up your WorkBook before attempting to make changes.
--------------------------------------------------------------------------------------------------------------

I have some code that is supposed to clean data in a
particular cell. The data is part numbers. Example...

A1 B1
P/N 1234-5 P/N 12345

When you enter the function cleanse(A1) in B1, the cleaned
part number will appear. It took out the dash. There are
other characters I want to do this with.

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
Cleaning data Torero Excel Worksheet Functions 3 November 28th 06 10:16 PM
Cleaning up data -- any way to globally fix this?? The Moose Excel Discussion (Misc queries) 3 November 26th 06 02:50 PM
Cleaning Data AMMark Excel Discussion (Misc queries) 1 October 19th 06 07:21 PM
Cleaning Up Data [email protected] Excel Discussion (Misc queries) 3 September 20th 06 04:40 PM
Cleaning Product Code list mike meyer Excel Worksheet Functions 6 April 11th 05 08:15 PM


All times are GMT +1. The time now is 07:52 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"