Insert apostrophe in front of numbers

This tutorial shows how to add an apostrophe (') in front of a numeric cell, meaning the cell comprises only numbers without any other characters of spaces, through the use of an Excel formula, with the IF and ISNUMBER functions or VBA

EXCEL FORMULA 1. Insert apostrophe in front of numbers using the IF and ISNUMBER functions

EXCEL

Hard coded formula
Insert apostrophe in front of numbers
Cell reference formula
Insert apostrophe in front of numbers
=IF(ISNUMBER(B5)=TRUE,"'"&B5,B5)
=IF(ISNUMBER(B7)=TRUE,$C$4&B7,B7)
GENERIC FORMULA

=IF(ISNUMBER(value)=TRUE,"'"&value,value)

ARGUMENTS
value: A value that is to be tested if it's a numeric cell and have an apostrophe inserted in front of number.

GENERIC FORMULA

=IF(ISNUMBER(value)=TRUE,apostrophe&value,value)

ARGUMENTS
value: A value that is to be tested if it's a numeric cell and have an apostrophe inserted in front of number.
apostrophe: A cell that contains the apostrophe sign (').

EXPLANATION

This formula uses the IF and ISNUMBER functions with the & sign to insert an apostrophe in front of a numeric cell.
Click on either the Hard Coded or Cell Reference button to view the formula that either has the apostrophe directly entered in the formula or referenced to a cell that captures the apostrophe sign that is to be inserted between the values that you want to combine.

By using the excel method the number is converted to text, however, if you want to retain the cell as a numeric value and still insert an apostrophe in front of a number you can use the following VBA approach.

VBA CODE 1. Insert apostrophe in front of numbers using VBA formula function

VBA

Hard coded against single cell
Sub Insert_apostrophe_in_front_of_numbers()
'declare variables
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'insert an apostrophe in front of a number
If IsNumeric(ws.Range("B5")) = True Then

ws.Range("C5") = "'" & ws.Range("B5")

Else

ws.Range("C5") = ws.Range("B5")

End If

End Sub

Cell reference against single cell
Sub Insert_apostrophe_in_front_of_numbers()
'declare variables
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'insert an apostrophe in front of a number
If IsNumeric(ws.Range("B7")) = True Then

ws.Range("C7") = ws.Range("C4") & ws.Range("B7")

Else

ws.Range("C7") = ws.Range("B7")

End If

End Sub

Hard coded against range of cells
Sub Insert_apostrophe_in_front_of_numbers()
'declare variables
Dim ws As Worksheet
Set ws = Worksheets("Analysis")

'insert an apostrophe in front of a number

For x = 5 To 8
If IsNumeric(ws.Range("B" & x)) = True Then

ws.Range("C" & x) = "'" & ws.Range("B" & x)

Else

ws.Range("C" & x) = ws.Range("B" & x)

End If

Next x

End Sub

Cell reference against range of cells
Sub Insert_apostrophe_in_front_of_numbers()
'declare variables
Dim ws As Worksheet
Set ws = Worksheets("Analysis")

'insert an apostrophe in front of a number

For x = 5 To 8
If IsNumeric(ws.Range("B" & x)) = True Then

ws.Range("C" & x) = ws.Range("C4") & ws.Range("B" & x)

Else

ws.Range("C" & x) = ws.Range("B" & x)

End If

Next x

End Sub

RELATED TOPICS

Related Topic Description Related Topic and Description
How to add a comma (,) to the end of a cell through the use of an Excel formula or VBA
How to insert a comma (,) before the first number in a cell through the use of an Excel formula or VBA
How to insert a comma (,) after the first number in a cell through the use of an Excel formula or VBA

RELATED FUNCTIONS

Related Functions Description Related Functions and Description
The Excel IF function performs a test on specified conditions entered into the formula and returns a specified value if the result is TRUE or another specified value if the result is FALSE
The Excel ISNUMBER function tests a specified value (cell) if it's a numeric value and returns TRUE if it's a text value or FALSE if it's not a numeric value