ISBN 13 and ISBN 10 validation function in VBA/Macro

nyounaki

New Member
Joined
Nov 9, 2020
Messages
8
Office Version
  1. 365
Platform
  1. Windows
HI ,
Looking for ISBN (10 and 13) validation specifically for ISBN 13 so I can used on VBA Macros , I saw some ISBN 10 validation , but couldn't find proper one for ISBN 13 ,
the function I can used in VBA like the following :
if fn_isValidISBN13('1234567890123') then
'do something
end if
will be also to have one validation function for ISBN13 and ISBN10
can you help please !
Thanks
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
HI ,
Looking for ISBN (10 and 13) validation specifically for ISBN 13 so I can used on VBA Macros , I saw some ISBN 10 validation , but couldn't find proper one for ISBN 13 ,
the function I can used in VBA like the following :
if fn_isValidISBN13('1234567890123') then
'do something
end if
will be also to have one validation function for ISBN13 and ISBN10
can you help please !
Thanks
Try this. Make sure to verify the results
VBA Code:
Public Function ISBN_Validation(CodeN As String, ISBN10 As Boolean, ISBN13 As Boolean) as boolean

Dim Number_ITR As Long, Check_Digit As String, EO As Long, Final_Sum As Double

If (ISBN10 And ISBN13) Or (Not ISBN10 And Not ISBN13) Then
    MsgBox "Please choose either ISBN10 or ISBN13)"
    Exit Function
End If

Check_Digit = Right(CodeN, 1)

EO = 0

For Number_ITR = 1 To Len(CodeN) - 1
   
    If IsNumeric(Mid(CodeN, Number_ITR, 1)) Then
   
        EO = EO + 1
       
        If ISBN13 Then
       
            If EO Mod 2 = 0 Then
                Final_Sum = (3 * CLng(Mid(CodeN, Number_ITR, 1))) + Final_Sum
            Else
                Final_Sum = CLng(Mid(CodeN, Number_ITR, 1)) + Final_Sum
            End If
           
            If EO = 12 Then Exit For
           
        ElseIf ISBN10 Then
       
            Final_Sum = Final_Sum + ((11 - EO) * CLng(Mid(CodeN, Number_ITR, 1)))
           
            If EO = 9 Then Exit For
           
        End If
       
    End If
   
Next Number_ITR

If ISBN13 Then

    Final_Sum = 10 - (Final_Sum Mod 10)
   
    If Final_Sum = 10 Then Final_Sum = 0
   
    If Final_Sum = CLng(Check_Digit) Then ISBN_Validation = True
   
ElseIf ISBN10 Then

    Final_Sum = 11 - (Final_Sum Mod 11)
   
    If Final_Sum = 11 Then Final_Sum = 0
   
    If IsNumeric(Check_Digit) Then
   
        If Final_Sum = CLng(Check_Digit) Then ISBN_Validation = True
       
    ElseIf Final_Sum = 10 And UCase(Check_Digit) = "X" Then
   
        ISBN_Validation = True
   
    End If
   
End If

End Function
 
Upvote 0

Forum statistics

Threads
1,215,002
Messages
6,122,652
Members
449,092
Latest member
peppernaut

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