Solved

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

Posted on 2015-01-31
2
81 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
2 Comments
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
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
Comment Utility
It worked, just the way I had hoped.....

Thanks....
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now