Scrubbing a worksheet

cuetipper

Board Regular
Joined
Nov 9, 2018
Messages
67
So this seems it should be simple but i cant get it.
I want to remove all non alpha charectors from a spreadsheet but not the spaces, which is where i am getting issues.

So if I had [ "bob's Number*1 ten." ] the results would be [ bobs number1 ten ].


Any ideas?

Thanks.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Re: Scrubbing a wporksheet

try this

Code:
Sub Macro1()
'
' Macro1 Macro
'
Application.ScreenUpdating = False
With ActiveSheet
    Cells.Replace What:="""", Replacement:="", LookAt:=xlPart, SearchOrder _
        :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
    Cells.Replace What:="'", Replacement:="", LookAt:=xlPart, SearchOrder:= _
        xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
    Cells.Replace What:=".", Replacement:="", LookAt:=xlPart, SearchOrder:= _
        xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
    Cells.Replace What:="~*", Replacement:="", LookAt:=xlPart, SearchOrder _
        :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
        End With
Application.ScreenUpdating = True

End Sub

the tricky one is * where you have to preface with ~
 
Upvote 0
Re: Scrubbing a wporksheet

Here's a function that will only return alpha characters and space. If you want to include numbers as well, that can be added to the criteria if you want.
Code:
Function AlphaOnly(vTx As Range) As String
'
' Macro1 Macro
'
vIn = vTx.Value
vOut = ""
For i = 1 To Len(vIn)
    If (Mid(vIn, i, 1) >= "A" And Mid(vIn, i, 1) <= "Z") Or (Mid(vIn, i, 1) >= "a" And Mid(vIn, i, 1) <= "z") Or Mid(vIn, i, 1) = " " Then
        vOut = vOut & Mid(vIn, i, 1)
    End If
Next
AlphaOnly = vOut
'
End Function
 
Upvote 0
Re: Scrubbing a wporksheet

mole999, thanks. But that deleted all my data.


Gr00007, how do I run the funtion?
 
Upvote 0
Re: Scrubbing a wporksheet

Use in an empty cell where X2 is the cell you want scrubbed:
=AlphaOnly(X2)
You can then copy it down.
The function needs to be in the workbook you're using, OR if you have a repository for functions or whatever in another workbook you could use the Insert Function on the Formulas tab, select user functions, and you should find it.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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