Remove preceding apostrophes.....

DougDodge
DougDodge used Ask the Experts™
on
I receive many dumps from a Database that has every cell with a leading apostrophe. The attached sheet has a macro that when run will remove the apostrophe from cells that contain dates or numbers, but will not remove the preceding apostrophe from text. I hope to get the macro modified to remove all preceding apostrophes.
Test-Worksheet---Copy.xlsm
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Try something like this.
Sub DeleteApostrophes()
Dim rCell As Range

For Each rCell In ActiveSheet.UsedRange
If rCell.PrefixCharacter = "'" Then
rCell.Value = rCell.Value
End If
Next rCell

End Sub

Open in new window

Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015
Commented:
Try this...
The following code will remove the apostrophe from both the text and numeric cells. You may need to format the number cells again once the apostrophe is removed from all the cells on the activesheet.

Sub RemoveApostrophe()
Dim cell As Range
Dim lc As Long
lc = Cells(1, Columns.Count).End(xlToLeft).Column + 1
Cells(1, lc).Copy
For Each cell In ActiveSheet.UsedRange
   cell.PasteSpecial xlPasteAll, operation:=xlAdd
Next cell
End Sub

Open in new window

Professor JMicrosoft Excel Expert
Top Expert 2014

Commented:
DougDodge

in reality those are not apostrophies, although they look like apostrophies.

you can fix this without any macro select all of your data by Control + A and then  as shown in below screenshot click on clear formatting.

2016-02-03-19_03_18-New-notification.png
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Subodh Tiwari (Neeraj)Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015

Commented:
Well done Professor.
Sometimes Excel inbuilt features do wonders. Very clever one.
Professor JMicrosoft Excel Expert
Top Expert 2014

Commented:
thanks Sktneer :-)

Author

Commented:
This works perfectly, thank you.
Professor JMicrosoft Excel Expert
Top Expert 2014

Commented:
DougDodge
 I am okay with that solution you selected as accepted , out of curiosity did that code really work? Becuase the file you uploaded had no apostrophes but it was just a format that needed clearance of format .

Author

Commented:
Yes, the code really did work.

Author

Commented:
As ProfessorJimJam pointed out, they really are not apostrophes, but they are there if you click in any given cell.
Professor JMicrosoft Excel Expert
Top Expert 2014

Commented:
Thanks Doug for feedback
Subodh Tiwari (Neeraj)Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015

Commented:
@DougDodge
As the solution provided by Professor also works and simplest to adopt, please take a moment to use Request Attention to split the points. I will welcome if you do so.
Professor JMicrosoft Excel Expert
Top Expert 2014

Commented:
Sktneer,

Please :-) it is alright

No need to split points. Your solution works better for Doug , so that is what matters


Cheers
JJ

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial