need to debug a little macros.

Mehman

New Member
Joined
Jan 19, 2017
Messages
9
Is there anyone who can debug the macros in the attached .xlsm file.

The professional can easily correct the mistake. I'm not able to do that.

The process:
It is a simple VIN Decoder. I load the list of VIN numbers of cars, and it shows me information about the cars.

The Problem:
Validate VIN - works good.
Decode VIN - returns 'Run-time error 1004'

i need it to work.

The link for macros is the next: http://files.gove.net/shares/files/10f/aec57/Online_VIN_Decoder.xlsm
The link for pdf is the next: http://files.gove.net/shares/files/10f/aec57/Online_VIN_Decoder.pdf

The files have been checked and don't have any viruses!

Who can help me?

Waiting your replies.

Thank you,

M.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
but you might be deliberately spreading viruses... so I never download - make up a pretend sheet and make clear your desired output
 
Upvote 0
[TABLE="width: 704"]
<colgroup><col width="64" span="11" style="width:48pt"> </colgroup><tbody>[TR]
[TD="width: 64"]vin[/TD]
[TD="width: 64"]car[/TD]
[TD="width: 64"]reg[/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[/TR]
[TR]
[TD]v1[/TD]
[TD]ford[/TD]
[TD]r131[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]v2[/TD]
[TD]mini[/TD]
[TD]r143[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]v3[/TD]
[TD]fiat[/TD]
[TD]r155[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]v4[/TD]
[TD]renault[/TD]
[TD]r167[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]v5[/TD]
[TD]ford[/TD]
[TD]r179[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"]input a vin number[/TD]
[TD]v7[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]v6[/TD]
[TD]mini[/TD]
[TD]r191[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]v7[/TD]
[TD]fiat[/TD]
[TD]r203[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]car[/TD]
[TD]fiat[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]v8[/TD]
[TD]renault[/TD]
[TD]r215[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]reg[/TD]
[TD]r203[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]v9[/TD]
[TD]ford[/TD]
[TD]r227[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]v10[/TD]
[TD]mini[/TD]
[TD]r239[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"]input a reg number[/TD]
[TD]r227[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]vin num[/TD]
[TD][/TD]
[TD]v9[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"]is this what you want[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Sorry, Oldbrewer,
I have to write VIN numbers:
[TABLE="width: 143"]
<colgroup><col></colgroup><tbody>[TR]
[TD]VIN No.[/TD]
[/TR]
[TR]
[TD]2G4WS52J331220521 [/TD]
[/TR]
[TR]
[TD]2G1WL52J3Y1268537

And it mus reply me:
[TABLE="width: 339"]
<colgroup><col><col><col><col></colgroup><tbody>[TR]
[TD]Year[/TD]
[TD]Make[/TD]
[TD]Model[/TD]
[TD]District No.[/TD]
[/TR]
[TR]
[TD]2003[/TD]
[TD]BUICK [/TD]
[TD]CENTURY [/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]2000[/TD]
[TD]CHEV [/TD]
[TD]LUMINA [/TD]
[TD]1[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
If you could read a pdf file from a link (without download) it would be better.
It has the instructions and pics how to use the file.

Thank you in advance.
 
Upvote 0
Mehman
need to debug a little macros.

Is there anyone who can debug the macros in the attached .xlsm file.

Post your code in the thread and in code tags please.
 
Last edited:
Upvote 0
Post your code in the thread and in code tags please.

Hi Mark. Check it, please. I don't know - Did I do right?

Code:
Option ExplicitDim aWeight() As Integer
Dim aAutoData() As Variant
Dim Row As Integer


Sub LoadArrays()
    Dim r As Integer
    ReDim aTransliterate(35, 1)
    ReDim aWeight(16)
    ReDim aAutoData(1, 21)
    
    Application.ScreenUpdating = False
    Sheets("data").visible = True
    
    'Load Arrays
    Sheets("data").Select
    
    Range("A2").Select
    For r = 0 To UBound(aWeight)
        aWeight(r) = ActiveCell.Value
        ActiveCell.Offset(1, 0).Select
    Next
    
    Range("D2").Select
    For r = 0 To UBound(aAutoData, 2)
        aAutoData(0, r) = ActiveCell.Value
        ActiveCell.Offset(1, 0).Select
    Next
    
    Sheets("VIN List").Select
    Sheets("data").visible = False
    Application.ScreenUpdating = True
    
End Sub


Sub LoadFile()
    Dim FileName As String
    Dim FileType As String
    
    Application.ScreenUpdating = False
    'get name and path of file.
    FileName = Application.GetOpenFilename
    
    If FileName = "False" Then
        Application.ScreenUpdating = True
        Exit Sub
    End If
        
    If UCase(Right(FileName, 4)) <> ".TXT" Then
        Application.ScreenUpdating = True
        MsgBox "VIN file must be a text file"
        Exit Sub
    End If
        
    'clear all old VINs
    Rows("2:2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Clear
    'Load new VINs
    Range("A2").Select
    ReadFile (FileName)


    
    Application.ScreenUpdating = True
    Range("A2").Select
    MsgBox "VINs Loaded Successfully."
    
End Sub


Sub ReadFile(FilePath As String) 'FilePath must containt the full file path and name
'Must use Tools > References > Microsoft Scripting Runtime
    Dim sText As String
    Dim oFSO As New FileSystemObject
    Dim oFS As Object


    Set oFS = oFSO.OpenTextFile(FilePath)
    Range("A2").Select
    
    Do Until oFS.AtEndOfStream
        ActiveCell.Value = oFS.ReadLine
        ActiveCell.Offset(1, 0).Select
    Loop
    Range("A1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Columns.AutoFit
    Selection.NumberFormat = "@"
    Range("A2").Select
        
End Sub


Sub VINValidator()
'calls the ChkVIN function to validate the VIN
    Range("A2").Select
    Do While ActiveCell.Value <> ""
        ActiveCell.Offset(0, 1).Value = ChkVIN(ActiveCell.Value)
        ActiveCell.Offset(1, 0).Select
    Loop


End Sub


Function ChkVIN(VIN As String) As String
'Returns "Yes" if VIN is valid and "No" if its not valid
    Dim aVIN(16) As String
    Dim aValue(16) As Integer
    Dim aProduct(16) As Integer
    Dim x As Integer
    Dim ChkDigit As String
    Dim ProdSum As Integer


    ProdSum = 0
    'transliterate VIN digits, multiply values by weith, place results in aProduct array, and sum all products
    For x = 0 To UBound(aVIN)
        aVIN(x) = UCase(Mid(VIN, x + 1, 1))
        If x = 8 Then
            'the check digit must be transliterated to a 0.
            aValue(x) = 0
        Else
            aValue(x) = Transliterate(aVIN(x))
        End If
        
        aProduct(x) = aWeight(x) * aValue(x)
        ProdSum = ProdSum + aProduct(x)
        
        If aValue(x) = -1 Or aProduct(x) = -1 Then
            ChkVIN = "No"
            Exit Function
        End If
    Next x
    
    ChkDigit = ProdSum Mod 11
    If ChkDigit = 10 Then
        ChkDigit = "X"
    End If
    'aVIN(8) contains the supplied check digit while ChkDigit contains the calculated check digit
    If ChkDigit <> aVIN(8) Then
        ChkVIN = "No"
        Exit Function
    Else
        ChkVIN = "Yes"
    End If
    
    'clear out local variables and arrays
    For x = 0 To UBound(aVIN)
        aVIN(x) = Empty
    Next
    For x = 0 To UBound(aValue)
        aValue(x) = Empty
    Next
    For x = 0 To UBound(aProduct)
        aProduct(x) = Empty
    Next
    x = Empty
    ChkDigit = Empty
    ProdSum = Empty
    
End Function


Function Transliterate(Value As String) As Integer
'Transliterate will return a -1 if Value = I, O, Q, or some other invalid character
    Select Case UCase(Value)
        Case "A"
            Transliterate = 1
            Exit Function
        Case "B"
            Transliterate = 2
            Exit Function
        
        Case "C"
            Transliterate = 3
            Exit Function
            
        Case "D"
            Transliterate = 4
            Exit Function
        
        Case "E"
            Transliterate = 5
            Exit Function
            
        Case "F"
            Transliterate = 6
            Exit Function
        
        Case "G"
            Transliterate = 7
            Exit Function
        
        Case "H"
            Transliterate = 8
            Exit Function
            
        Case "I"
            Transliterate = -1
            Exit Function
            
        Case "J"
            Transliterate = 1
            Exit Function
        
        Case "K"
            Transliterate = 2
            Exit Function
            
        Case "L"
            Transliterate = 3
            Exit Function
            
        Case "M"
            Transliterate = 4
            Exit Function
        
        Case "N"
            Transliterate = 5
            Exit Function
            
        Case "O"
            Transliterate = -1
            Exit Function
            
        Case "P"
            Transliterate = 7
            Exit Function
            
        Case "Q"
            Transliterate = -1
            Exit Function


        Case "R"
            Transliterate = 9
            Exit Function
            
        Case "S"
            Transliterate = 2
            Exit Function


        Case "T"
            Transliterate = 3
            Exit Function


        Case "U"
            Transliterate = 4
            Exit Function


        Case "V"
            Transliterate = 5
            Exit Function
        
        Case "W"
            Transliterate = 6
            Exit Function
        
        Case "X"
            Transliterate = 7
            Exit Function
        
        Case "Y"
            Transliterate = 8
            Exit Function
        
        Case "Z"
            Transliterate = 9
            Exit Function
            
        Case "1"
            Transliterate = 1
            Exit Function
        
        Case "2"
            Transliterate = 2
            Exit Function
        
        Case "3"
            Transliterate = 3
            Exit Function
        
        Case "4"
            Transliterate = 4
            Exit Function
        
        Case "5"
            Transliterate = 5
            Exit Function
        
        Case "6"
            Transliterate = 6
            Exit Function
        
        Case "7"
            Transliterate = 7
            Exit Function
        
        Case "8"
            Transliterate = 8
            Exit Function
        
        Case "9"
            Transliterate = 9
            Exit Function
        
        Case "0"
            Transliterate = 0
            Exit Function
        
        Case Else
            Transliterate = -1
            Exit Function
        
        End Select
        
End Function


Sub VINDecoder()
'Calls the LookupVINOnline and FetchData subroutines to decode the VIN
    Dim sVIN As String
    Dim sValid As String
    
    Sheets("vin list").Select
    Range("A2").Select
    Do While ActiveCell.Value <> Empty
        Row = ActiveCell.Row
        sVIN = ActiveCell.Value
        sValid = ActiveCell.Offset(0, 1).Value
        'Only lookup VINs that are valid
        If sValid = "" Then
            ActiveCell.Offset(0, 1).Value = ChkVIN(ActiveCell.Value)
            sValid = ActiveCell.Offset(0, 1).Value
        End If
        If sValid = "Yes" Then
            Application.ScreenUpdating = False
            LookupVINOnline sVIN
            FetchData
            Application.ScreenUpdating = True
        End If
        ActiveCell.Offset(1, 0).Select
    Loop
    
    MsgBox "VINs decoded successfully."


End Sub


Sub LookupVINOnline(VIN As String)
'looks up the VIN online and copies the data to the "VIN Data" sheet
    Dim sURL As String


    sURL = "URL;http://www.decodethis.com/Default.aspx?tabid=65&vin=" & VIN
    
    Sheets("vin data").visible = True
    Sheets("vin data").Select
    Range("A2").Select
    With Selection.QueryTable
        .Connection = sURL
        .WebSelectionType = xlSpecifiedTables
        .WebFormatting = xlWebFormattingNone
        .WebTables = """TableRight"""
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
    Sheets("vin data").visible = False
End Sub


Sub FetchData()
'Fetches the colletcted data from the "VIN Data" sheet and pastes it in the correct column in the "VIN List" sheet
'This function uses a dynamic array (aAutoData) to transfer the values from the "VIN Data" sheet to the "VIN List" sheet
    Dim rFind As Range
    Dim x As Integer
    Dim Count As Integer
    Dim OrigSize As Integer
    Dim NewSize As Integer
    'The aAutoData array contains a list of the data that will be searched for in the VIN Data sheet
    'the data for this array is contained in the "Data" sheet which is a hidden sheet
    OrigSize = UBound(aAutoData, 2)
    
    Sheets("vin data").visible = True
    Sheets("vin data").Select
    Range("A2").Select
    
    For x = 0 To UBound(aAutoData, 2)
        Set rFind = Cells.find(What:=aAutoData(0, x), LookAt:=xlWhole, SearchOrder:=xlByColumns)
        'if serached term is not found then assume the web query did not find any data for the VIN
        If rFind Is Nothing Then
            Sheets("VIN List").Select
            Cells(Row, 3).Value = "No data found."
            Exit Sub
        End If
        rFind.Select
        If ActiveCell.Offset(0, 1).Value = "" Then
            aAutoData(1, x) = "No data"
        Else
            aAutoData(1, x) = ActiveCell.Offset(0, 1).Value
        End If
    Next
    'The web query may return multiple entries for the "Transmission". The following code identifies
    'how many entries there are for the transmission and adjusts the aAutoData to be able to hold all the data
    ActiveCell.Offset(1, 0).Select
    Do While ActiveCell.Value = ""
        Count = Count + 1
        ActiveCell.Offset(1, 0).Select
    Loop
    If Count <> 0 Then
        NewSize = OrigSize + Count
        ReDim Preserve aAutoData(1, NewSize)
        ActiveCell.Offset(-Count, 0).Select
           For x = 1 To Count
               aAutoData(1, OrigSize + x) = ActiveCell.Offset(0, 1).Value
               ActiveCell.Offset(1, 0).Select
           Next
    End If
    'Place the data from the aAutoData array into the correct columns in the "VIN List" sheet
    Sheets("vin data").visible = False
    Sheets("VIN List").Select
    Cells(Row, 3).Select
    For x = 0 To UBound(aAutoData, 2)
        Selection.NumberFormat = "@" 'turn cell format = text
        ActiveCell.Value = aAutoData(1, x)
        Selection.EntireColumn.AutoFit
        ActiveCell.Offset(0, 1).Select
    Next
    Cells(Row, 1).Select
    
    VINList.Select
    Sheets("vin data").visible = False
    
    'Clear data
    rFind = Empty
    ReDim Preserve aAutoData(1, 21)
    For x = 0 To UBound(aAutoData, 2)
        aAutoData(1, x) = Empty
    Next
    x = 0
    Count = 0
    OrigSize = Empty
    NewSize = Empty
    
End Sub
 
Upvote 0
Hi Mark. Check it, please. I don't know - Did I do right?

Code:
Option ExplicitDim aWeight() As Integer
Dim aAutoData() As Variant
Dim Row As Integer


Sub LoadArrays()
    Dim r As Integer
    ReDim aTransliterate(35, 1)
    ReDim aWeight(16)
    ReDim aAutoData(1, 21)
    
    Application.ScreenUpdating = False
    Sheets("data").visible = True
    
    'Load Arrays
    Sheets("data").Select
    
    Range("A2").Select
    For r = 0 To UBound(aWeight)
        aWeight(r) = ActiveCell.Value
        ActiveCell.Offset(1, 0).Select
    Next
    
    Range("D2").Select
    For r = 0 To UBound(aAutoData, 2)
        aAutoData(0, r) = ActiveCell.Value
        ActiveCell.Offset(1, 0).Select
    Next
    
    Sheets("VIN List").Select
    Sheets("data").visible = False
    Application.ScreenUpdating = True
    
End Sub


Sub LoadFile()
    Dim FileName As String
    Dim FileType As String
    
    Application.ScreenUpdating = False
    'get name and path of file.
    FileName = Application.GetOpenFilename
    
    If FileName = "False" Then
        Application.ScreenUpdating = True
        Exit Sub
    End If
        
    If UCase(Right(FileName, 4)) <> ".TXT" Then
        Application.ScreenUpdating = True
        MsgBox "VIN file must be a text file"
        Exit Sub
    End If
        
    'clear all old VINs
    Rows("2:2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Clear
    'Load new VINs
    Range("A2").Select
    ReadFile (FileName)


    
    Application.ScreenUpdating = True
    Range("A2").Select
    MsgBox "VINs Loaded Successfully."
    
End Sub


Sub ReadFile(FilePath As String) 'FilePath must containt the full file path and name
'Must use Tools > References > Microsoft Scripting Runtime
    Dim sText As String
    Dim oFSO As New FileSystemObject
    Dim oFS As Object


    Set oFS = oFSO.OpenTextFile(FilePath)
    Range("A2").Select
    
    Do Until oFS.AtEndOfStream
        ActiveCell.Value = oFS.ReadLine
        ActiveCell.Offset(1, 0).Select
    Loop
    Range("A1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Columns.AutoFit
    Selection.NumberFormat = "@"
    Range("A2").Select
        
End Sub


Sub VINValidator()
'calls the ChkVIN function to validate the VIN
    Range("A2").Select
    Do While ActiveCell.Value <> ""
        ActiveCell.Offset(0, 1).Value = ChkVIN(ActiveCell.Value)
        ActiveCell.Offset(1, 0).Select
    Loop


End Sub


Function ChkVIN(VIN As String) As String
'Returns "Yes" if VIN is valid and "No" if its not valid
    Dim aVIN(16) As String
    Dim aValue(16) As Integer
    Dim aProduct(16) As Integer
    Dim x As Integer
    Dim ChkDigit As String
    Dim ProdSum As Integer


    ProdSum = 0
    'transliterate VIN digits, multiply values by weith, place results in aProduct array, and sum all products
    For x = 0 To UBound(aVIN)
        aVIN(x) = UCase(Mid(VIN, x + 1, 1))
        If x = 8 Then
            'the check digit must be transliterated to a 0.
            aValue(x) = 0
        Else
            aValue(x) = Transliterate(aVIN(x))
        End If
        
        aProduct(x) = aWeight(x) * aValue(x)
        ProdSum = ProdSum + aProduct(x)
        
        If aValue(x) = -1 Or aProduct(x) = -1 Then
            ChkVIN = "No"
            Exit Function
        End If
    Next x
    
    ChkDigit = ProdSum Mod 11
    If ChkDigit = 10 Then
        ChkDigit = "X"
    End If
    'aVIN(8) contains the supplied check digit while ChkDigit contains the calculated check digit
    If ChkDigit <> aVIN(8) Then
        ChkVIN = "No"
        Exit Function
    Else
        ChkVIN = "Yes"
    End If
    
    'clear out local variables and arrays
    For x = 0 To UBound(aVIN)
        aVIN(x) = Empty
    Next
    For x = 0 To UBound(aValue)
        aValue(x) = Empty
    Next
    For x = 0 To UBound(aProduct)
        aProduct(x) = Empty
    Next
    x = Empty
    ChkDigit = Empty
    ProdSum = Empty
    
End Function


Function Transliterate(Value As String) As Integer
'Transliterate will return a -1 if Value = I, O, Q, or some other invalid character
    Select Case UCase(Value)
        Case "A"
            Transliterate = 1
            Exit Function
        Case "B"
            Transliterate = 2
            Exit Function
        
        Case "C"
            Transliterate = 3
            Exit Function
            
        Case "D"
            Transliterate = 4
            Exit Function
        
        Case "E"
            Transliterate = 5
            Exit Function
            
        Case "F"
            Transliterate = 6
            Exit Function
        
        Case "G"
            Transliterate = 7
            Exit Function
        
        Case "H"
            Transliterate = 8
            Exit Function
            
        Case "I"
            Transliterate = -1
            Exit Function
            
        Case "J"
            Transliterate = 1
            Exit Function
        
        Case "K"
            Transliterate = 2
            Exit Function
            
        Case "L"
            Transliterate = 3
            Exit Function
            
        Case "M"
            Transliterate = 4
            Exit Function
        
        Case "N"
            Transliterate = 5
            Exit Function
            
        Case "O"
            Transliterate = -1
            Exit Function
            
        Case "P"
            Transliterate = 7
            Exit Function
            
        Case "Q"
            Transliterate = -1
            Exit Function


        Case "R"
            Transliterate = 9
            Exit Function
            
        Case "S"
            Transliterate = 2
            Exit Function


        Case "T"
            Transliterate = 3
            Exit Function


        Case "U"
            Transliterate = 4
            Exit Function


        Case "V"
            Transliterate = 5
            Exit Function
        
        Case "W"
            Transliterate = 6
            Exit Function
        
        Case "X"
            Transliterate = 7
            Exit Function
        
        Case "Y"
            Transliterate = 8
            Exit Function
        
        Case "Z"
            Transliterate = 9
            Exit Function
            
        Case "1"
            Transliterate = 1
            Exit Function
        
        Case "2"
            Transliterate = 2
            Exit Function
        
        Case "3"
            Transliterate = 3
            Exit Function
        
        Case "4"
            Transliterate = 4
            Exit Function
        
        Case "5"
            Transliterate = 5
            Exit Function
        
        Case "6"
            Transliterate = 6
            Exit Function
        
        Case "7"
            Transliterate = 7
            Exit Function
        
        Case "8"
            Transliterate = 8
            Exit Function
        
        Case "9"
            Transliterate = 9
            Exit Function
        
        Case "0"
            Transliterate = 0
            Exit Function
        
        Case Else
            Transliterate = -1
            Exit Function
        
        End Select
        
End Function


Sub VINDecoder()
'Calls the LookupVINOnline and FetchData subroutines to decode the VIN
    Dim sVIN As String
    Dim sValid As String
    
    Sheets("vin list").Select
    Range("A2").Select
    Do While ActiveCell.Value <> Empty
        Row = ActiveCell.Row
        sVIN = ActiveCell.Value
        sValid = ActiveCell.Offset(0, 1).Value
        'Only lookup VINs that are valid
        If sValid = "" Then
            ActiveCell.Offset(0, 1).Value = ChkVIN(ActiveCell.Value)
            sValid = ActiveCell.Offset(0, 1).Value
        End If
        If sValid = "Yes" Then
            Application.ScreenUpdating = False
            LookupVINOnline sVIN
            FetchData
            Application.ScreenUpdating = True
        End If
        ActiveCell.Offset(1, 0).Select
    Loop
    
    MsgBox "VINs decoded successfully."


End Sub


Sub LookupVINOnline(VIN As String)
'looks up the VIN online and copies the data to the "VIN Data" sheet
    Dim sURL As String


    sURL = "URL;http://www.decodethis.com/Default.aspx?tabid=65&vin=" & VIN
    
    Sheets("vin data").visible = True
    Sheets("vin data").Select
    Range("A2").Select
    With Selection.QueryTable
        .Connection = sURL
        .WebSelectionType = xlSpecifiedTables
        .WebFormatting = xlWebFormattingNone
        .WebTables = """TableRight"""
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
    Sheets("vin data").visible = False
End Sub


Sub FetchData()
'Fetches the colletcted data from the "VIN Data" sheet and pastes it in the correct column in the "VIN List" sheet
'This function uses a dynamic array (aAutoData) to transfer the values from the "VIN Data" sheet to the "VIN List" sheet
    Dim rFind As Range
    Dim x As Integer
    Dim Count As Integer
    Dim OrigSize As Integer
    Dim NewSize As Integer
    'The aAutoData array contains a list of the data that will be searched for in the VIN Data sheet
    'the data for this array is contained in the "Data" sheet which is a hidden sheet
    OrigSize = UBound(aAutoData, 2)
    
    Sheets("vin data").visible = True
    Sheets("vin data").Select
    Range("A2").Select
    
    For x = 0 To UBound(aAutoData, 2)
        Set rFind = Cells.find(What:=aAutoData(0, x), LookAt:=xlWhole, SearchOrder:=xlByColumns)
        'if serached term is not found then assume the web query did not find any data for the VIN
        If rFind Is Nothing Then
            Sheets("VIN List").Select
            Cells(Row, 3).Value = "No data found."
            Exit Sub
        End If
        rFind.Select
        If ActiveCell.Offset(0, 1).Value = "" Then
            aAutoData(1, x) = "No data"
        Else
            aAutoData(1, x) = ActiveCell.Offset(0, 1).Value
        End If
    Next
    'The web query may return multiple entries for the "Transmission". The following code identifies
    'how many entries there are for the transmission and adjusts the aAutoData to be able to hold all the data
    ActiveCell.Offset(1, 0).Select
    Do While ActiveCell.Value = ""
        Count = Count + 1
        ActiveCell.Offset(1, 0).Select
    Loop
    If Count <> 0 Then
        NewSize = OrigSize + Count
        ReDim Preserve aAutoData(1, NewSize)
        ActiveCell.Offset(-Count, 0).Select
           For x = 1 To Count
               aAutoData(1, OrigSize + x) = ActiveCell.Offset(0, 1).Value
               ActiveCell.Offset(1, 0).Select
           Next
    End If
    'Place the data from the aAutoData array into the correct columns in the "VIN List" sheet
    Sheets("vin data").visible = False
    Sheets("VIN List").Select
    Cells(Row, 3).Select
    For x = 0 To UBound(aAutoData, 2)
        Selection.NumberFormat = "@" 'turn cell format = text
        ActiveCell.Value = aAutoData(1, x)
        Selection.EntireColumn.AutoFit
        ActiveCell.Offset(0, 1).Select
    Next
    Cells(Row, 1).Select
    
    VINList.Select
    Sheets("vin data").visible = False
    
    'Clear data
    rFind = Empty
    ReDim Preserve aAutoData(1, 21)
    For x = 0 To UBound(aAutoData, 2)
        aAutoData(1, x) = Empty
    Next
    x = 0
    Count = 0
    OrigSize = Empty
    NewSize = Empty
    
End Sub

[TABLE="width: 1162"]
<colgroup><col><col span="8"><col><col span="5"></colgroup><tbody>[TR]
[TD]2G4WS52J331220521[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2G1WL52J3Y1268537[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]2G4WS52J331220517[/TD]
[TD="align: right"]2003[/TD]
[TD]ford[/TD]
[TD]tourer[/TD]
[TD="align: right"]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]And it mus reply me:[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]2G4WS52J331220518[/TD]
[TD="align: right"]2003[/TD]
[TD]chev[/TD]
[TD]offroad[/TD]
[TD="align: right"]2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Year[/TD]
[TD]Make[/TD]
[TD]Model[/TD]
[TD="colspan: 2"]District No.[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]2G4WS52J331220519[/TD]
[TD="align: right"]2003[/TD]
[TD]dodge[/TD]
[TD]truck[/TD]
[TD="align: right"]3[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]2003[/TD]
[TD]BUICK[/TD]
[TD]CENTURY[/TD]
[TD="align: right"]1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]2G4WS52J331220520[/TD]
[TD="align: right"]2003[/TD]
[TD]chev[/TD]
[TD]limo[/TD]
[TD="align: right"]2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]2003[/TD]
[TD]BUICK[/TD]
[TD]CENTURY[/TD]
[TD="align: right"]5[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]2G4WS52J331220521[/TD]
[TD="align: right"]2003[/TD]
[TD]BUICK[/TD]
[TD]CENTURY[/TD]
[TD="align: right"]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]2G4WS52J331220522[/TD]
[TD="align: right"]2003[/TD]
[TD]ford[/TD]
[TD]tourer[/TD]
[TD="align: right"]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]2G4WS52J331220523[/TD]
[TD="align: right"]2003[/TD]
[TD]chev[/TD]
[TD]offroad[/TD]
[TD="align: right"]2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]2G4WS52J331220524[/TD]
[TD="align: right"]2003[/TD]
[TD]dodge[/TD]
[TD]truck[/TD]
[TD="align: right"]3[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]2G4WS52J331220525[/TD]
[TD="align: right"]2003[/TD]
[TD]chev[/TD]
[TD]limo[/TD]
[TD="align: right"]2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]2G4WS52J331220526[/TD]
[TD="align: right"]2003[/TD]
[TD]ford[/TD]
[TD]limo[/TD]
[TD="align: right"]3[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]2G1WL52J3Y1268537[/TD]
[TD="align: right"]2003[/TD]
[TD]BUICK[/TD]
[TD]CENTURY[/TD]
[TD="align: right"]5[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]2G4WS52J331220541[/TD]
[TD="align: right"]2003[/TD]
[TD]ford[/TD]
[TD]tourer[/TD]
[TD="align: right"]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]2G4WS52J331220561[/TD]
[TD="align: right"]2003[/TD]
[TD]chev[/TD]
[TD]offroad[/TD]
[TD="align: right"]2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]2G4WS52J331220571[/TD]
[TD="align: right"]2003[/TD]
[TD]dodge[/TD]
[TD]truck[/TD]
[TD="align: right"]3[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]2G4WS52J331220581[/TD]
[TD="align: right"]2003[/TD]
[TD]chev[/TD]
[TD]limo[/TD]
[TD="align: right"]2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]2G4WS52J331220591[/TD]
[TD="align: right"]2003[/TD]
[TD]ford[/TD]
[TD]limo[/TD]
[TD="align: right"]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]2G4WS52J331220592[/TD]
[TD="align: right"]2003[/TD]
[TD]ford[/TD]
[TD]tourer[/TD]
[TD="align: right"]2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]2G4WS52J331220593[/TD]
[TD="align: right"]2003[/TD]
[TD]chev[/TD]
[TD]offroad[/TD]
[TD="align: right"]3[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2G4WS52J331220521[/TD]
[TD="align: right"]2003[/TD]
[TD]BUICK[/TD]
[TD]CENTURY[/TD]
[TD="align: right"]1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2G1WL52J3Y1268537[/TD]
[TD="align: right"]2003[/TD]
[TD]BUICK[/TD]
[TD]CENTURY[/TD]
[TD="align: right"]5[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="colspan: 3"]formula giving first 2003[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="colspan: 5"]=OFFSET($J$2,MATCH($A23,$J$3:$J$20,0),1)[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,774
Members
452,353
Latest member
strainu

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