Solved

How do I clean the data in a cell or special characters, spaces, and carriage returns?

Posted on 2015-01-31
2
87 Views
Last Modified: 2016-02-10
I am trying to clean and normalize data. Cells have carriage returns in them (Alt+Enter), special characters (%^*)/!~), and blank non printing characters. I have come across a few different methods, but each is a separate operation.

Is there a way to select the cells in question, and have a macro perform it all?

The attached file has the three different processes that I have found so far. Two are subs and one is a function. I am hoping to combine them so that one macro can do all three exercises at once.

Thanks for having a look....
Remove-Returns-And-Special-Characters.xl
0
Comment
Question by:DougDodge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 51

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 40582390
Hi,

pls try

Sub RemoveAll()
Dim cel
Dim strTmp, strSpecialChars
Dim i

For Each cel In ActiveSheet.UsedRange
    strTmp = Trim(Application.Clean(Replace(cel, Chr(10), " ")))
    strSpecialChars = "\/:*?™""®<>|.&@#(_+`©~);-+=^$!,'" 'This is your list of characters to be removed
    
    For i = 1 To Len(strSpecialChars)
        strTmp = Replace$(strTmp, Mid$(strSpecialChars, i, 1), "") 'this will remove spaces
    Next
    strTmp = Replace$(strTmp, "  ", " ")
    cel.Value = strTmp
Next
    
End Sub

Open in new window

Regards
0
 

Author Comment

by:DougDodge
ID: 40583208
It worked, just the way I had hoped.....

Thanks....
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question