Help formatting ISBN-10 and ISBN-13 data

redhots4

Board Regular
Joined
Aug 30, 2004
Messages
136
Office Version
  1. 365
Platform
  1. MacOS
I'm a self-proclaimed bookworm. There, I've said it. And as a data junkie, I maintain a library catalog in Excel. all books have either a 10- or 13-digit ISBN number.

I need help formatting these as follows:

0399136150 should display as 0-399-13615-0
039914563X should display as 0-399-14563-X (note it ends in a letter not a number!)
9780870212857 should display as 978-08-70212-85-7

I think I have the ISBN-13 (last row) figured out using 000-00-00000-00-0 in Custom number formatting. The ISBN-10 formatting works fine except for the ISBNs ending in X.

How do I solve this? Thanks!!
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
How about using VBA to format them.

Book2
A
10-399-13615-0
20-399-13615-X
3978-08-70212-85-7
Sheet1


VBA Code:
Sub ISBN()
Dim r As Range:         Set r = Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
Dim AR() As Variant:    AR = r.Value2

For i = 1 To UBound(AR)
    If Len(AR(i, 1)) = 10 Then
        AR(i, 1) = Format(AR(i, 1), "@-@@@-@@@@@-@")
    Else
        AR(i, 1) = Format(AR(i, 1), "@@@-@@-@@@@@-@@-@")
    End If
Next i

r.Value2 = AR
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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