|
本人是菜鸟一个!![]()
因为工作关系,本人经常要在EXCEL表格里输入集装箱号,而集装箱号是有一定校验规则的,如果箱号输入错误,会导致很多麻烦,因此,本人希望能在EXCEL表中的某一列实现箱号自动校验,如果箱号输入错误,可自动提示。为此,本人在网上搜索了一个箱号校验的VB代码,但小弟却不知如何修改一下。,加载到EXCEL里去。
希望哪为大虾仗义执言,小弟不胜感激~!
![]()
附代码如下:
Function ISO_Checking(Container_Num As String, Optional output_option As Integer) As String
'**********************
'* Written by Russell *
'* PONL Wellington *
'**********************
' OUTPUT OPTIONS:
' 0 = Check Digit as output
' 1 = Full Container Number with calculated check Digit as output
' 2 = "OK" or "Non ISO Number"
' check digit optional for options 0 & 1 but full container number required for option 2.
' Note: Incorrect format eg space between prefix and numbers will cause error handler to end
' Function and return "Wrong Format"
Dim FirstChar As String
Dim SecondChar As String
Dim ThirdChar As String
Dim ForthChar As String
Dim FifthChar As Byte
Dim SixthChar As Byte
Dim SeventhChar As Byte
Dim EighthChar As Byte
Dim NinthChar As Byte
Dim TenthChar As Byte
Dim EleventhChar As Byte
Dim First_Convert As Byte
Dim Second_Convert As Byte
Dim Third_Convert As Byte
Dim Forth_Convert As Byte
Dim Added_Value As Currency
Dim Check_Digit As Byte
On Error GoTo errorhandler
FirstChar = UCase(Left(Container_Num, 1)) ' Split up container number to Characters
SecondChar = UCase(Mid(Container_Num, 2, 1))
ThirdChar = UCase(Mid(Container_Num, 3, 1))
ForthChar = UCase(Mid(Container_Num, 4, 1))
FifthChar = Mid(Container_Num, 5, 1)
SixthChar = Mid(Container_Num, 6, 1)
SeventhChar = Mid(Container_Num, 7, 1)
EighthChar = Mid(Container_Num, 8, 1)
NinthChar = Mid(Container_Num, 9, 1)
TenthChar = Mid(Container_Num, 10, 1)
EleventhChar = Right(Container_Num, 1)
Select Case FirstChar ' Convert first character of prefix to a number
Case Is = "A"
First_Convert = 10
Case Is = "B"
First_Convert = 12
Case Is = "C"
First_Convert = 13
Case Is = "D"
First_Convert = 14
Case Is = "E"
First_Convert = 15
Case Is = "F"
First_Convert = 16
Case Is = "G"
First_Convert = 17
Case Is = "H"
First_Convert = 18
Case Is = "I"
First_Convert = 19
Case Is = "J"
First_Convert = 20
Case Is = "K"
First_Convert = 21
Case Is = "L"
First_Convert = 23
Case Is = "M"
First_Convert = 24
Case Is = "N"
First_Convert = 25
Case Is = "O"
First_Convert = 26
Case Is = " "
First_Convert = 27
Case Is = "Q"
First_Convert = 28
Case Is = "R"
First_Convert = 29
Case Is = "S"
First_Convert = 30
Case Is = "T"
First_Convert = 31
Case Is = "U"
First_Convert = 32
Case Is = "V"
First_Convert = 34
Case Is = "W"
First_Convert = 35
Case Is = "X"
First_Convert = 36
Case Is = "Y"
First_Convert = 37
Case Is = "Z"
First_Convert = 38
End Select
Select Case SecondChar ' Convert second character of prefix to a number
Case Is = "A"
Second_Convert = 10
Case Is = "B"
Second_Convert = 12
Case Is = "C"
Second_Convert = 13
Case Is = "D"
Second_Convert = 14
Case Is = "E"
Second_Convert = 15
Case Is = "F"
Second_Convert = 16
Case Is = "G"
Second_Convert = 17
Case Is = "H"
Second_Convert = 18
Case Is = "I"
Second_Convert = 19
Ca |
|