Convert numbers to text by putting a single quotation mark (') in front of numbers

Dear Expert:

I need to convert numbers to text and put a tick (') mark/single quotation mark in front of every one of them.

I would like to have a macro solution and the macro should work ONLY on selected cells.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
Andreas HermleTeam leaderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi Andreas

Try this:

Sub ConvCells()
Dim cell As Range
For Each cell In Selection
  cell.Formula = "'" & cell.Formula
Next cell
End Sub

Open in new window


Try This

Sub ReplaceNumberasText()

Dim rng, cel As Range

Set rng = Selection

For Each cel In rng
    If IsNumeric(cel.Value) Then cel.Value = "'" & cel.Value
Next cel

End Sub
If you really need the apostrophe

Sub Example()
Dim rngCell As Range
On Error GoTo ExitPoint
Application.ScreenUpdating = False
For Each rngCell in Selection.Cells
     If IsNumeric(rngCell.Value) Then rngCell.Value = "'" & rngCell.Value
Next rngCell
Application.ScreenUpdating = True
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MSmaxImplementation ConsultantCommented:
hi please see sample file for solution
Andreas HermleTeam leaderAuthor Commented:
Dear all,

thank you very much for your great help. All solution are working. I therefore suggest splitting the points evenly.

Regards, Andreas
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.