Macro to remove apostrophe during data import

zeppelinmike

New Member
Joined
Jun 30, 2011
Messages
9
Excel 2003
Hello all, my Excel skills are limited and would appreciate your help. I have a spreadsheet which gets its data imported from another program. The problem is each cell has a apostrophe (') automatically added in front of it in each of the cells. This prevents problems when I'm carrying out a formula.

Any suggestions to automatically remove this during each import.

Many thanks for your support!:)
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
You can try this:

Code:
Sub ReplaceApos()
    Cells.Replace What:="'", Replacement:="", LookAt:=xlPart, SearchOrder:= _
        xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End Sub

Easiest way I find to set up a find/replace is to use the macro recorder, do your find/replace and then just snag the code (as I did here.)
 
Upvote 0
If I understand correctly what you want, so this code can help you:

Important: do a test with a copy of your workbook.

Note: Sheet1 is the sheet that have the data imported.

Code:
Sub ApostOut()
    Sheets("Sheet1").UsedRange.Value = Sheets("Sheet1").UsedRange.Value
End Sub

And tell us if it work.

Markmzz
 
Last edited:
Upvote 0
markmzz,
Your code works in my test sheet, except it will change all cells with formulas to the formula value. That can be fixed by only working with Constants like this:
Code:
Sub ClearApostrophe()
Set Rng = Range("A1").CurrentRegion
    For Each c In Rng.SpecialCells(xlCellTypeConstants, 2)
        c.Value = c.Value
    Next c
End Sub
 
Upvote 0
markmzz,
Your code works in my test sheet, except it will change all cells with formulas to the formula value. That can be fixed by only working with Constants like this:
Code:
Sub ClearApostrophe()
Set Rng = Range("A1").CurrentRegion
    For Each c In Rng.SpecialCells(xlCellTypeConstants, 2)
        c.Value = c.Value
    Next c
End Sub

Datsmart,

Thank you for your note.

Markmz
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,334
Members
452,907
Latest member
Roland Deschain

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