Query to Remove Spaces, Characters from a list

JGARDNER-AIT

Board Regular
Joined
May 15, 2007
Messages
149
Hello,
I have a long list of part numbers in a field called MPN. I'm trying to remove all characters and spaces. I want to only leave numeric and alpha numeric text only.

Anyones help would be greatly appreciated.
Thanks - Josh
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi, Use the following code. The code tests for the special charecters in the activecell and deletes it. However you can check this in a range by adding one more loop. Hope this helps.

Code:
Sub test()
TxtLengh = Len(ActiveCell.Value)
    For i = 1 To TxtLengh
    If i > Len(ActiveCell.Value) Then Exit Sub
        MyVal = Mid(ActiveCell.Value, i, 1)
      If (Asc(MyVal) > 47 And Asc(MyVal) < 58) Or _
         (Asc(MyVal) > 64 And Asc(MyVal) < 91) Or _
         (Asc(MyVal) > 96 And Asc(MyVal) < 123) Then
         Else
         LResult = Replace(ActiveCell.Value, Chr(Asc(MyVal)), "")
            ActiveCell.Value = LResult
            i = i - 1
      End If
    Next i
End Sub
 
Upvote 0
Use the function either: paste the following code in a module and use the function. Ex:, If you are checking a string in cell A1 then type =SplChrDelete(A1) in cell A2. Hope this helps.
Code:
Function SplChrDelete(Target As String)
TxtLengh = Len(Target)
    For i = 1 To TxtLengh
    If i > Len(Target) Then Exit Function
        MyVal = Mid(Target, i, 1)
      If (Asc(MyVal) > 47 And Asc(MyVal) < 58) Or _
         (Asc(MyVal) > 64 And Asc(MyVal) < 91) Or _
         (Asc(MyVal) > 96 And Asc(MyVal) < 123) Then
         Else
         LResult = Replace(Target, Chr(Asc(MyVal)), "")
            Target = LResult
            SplChrDelete = LResult
            i = i - 1
      End If
    Next i
End Function
 
Upvote 0
I am sorry JOSH, I thought you are looking for help in Excel.

But you can use the Function code in Access aswell.
 
Upvote 0

Forum statistics

Threads
1,214,424
Messages
6,119,401
Members
448,893
Latest member
AtariBaby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top