Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to write code that can replace a text by another text

Status
Not open for further replies.

chaupha

Programmer
Oct 3, 2002
3
US
I have a file in excel which contains VIN (Vehicle Indentification Number). How to write a code that can convert the second character of that vin to a make such as Toyota or Dodge...
For example:
1Y1SK6466MZ071799
1GNDT13S122516622
1GCEK14V9YE424125
1G1JC52F237124818
These are the VIN, I want to convert the 2nd and 3rd character which is Y1, or GN to a make that character stand for. Does it has a code or program in Excell that can convert it? I prefer to write VB in Excel.
Thanks.
 
Well, decoding VINs is a real art. They changed layout over time, so . . . Here's a sample VBA function that you can incorporate in an Excel worksheet to decode based on the second character of the VIN.
Code:
Function VINDecode(VIN As Range) As String

Select Case Mid(VIN, 2, 1) ' check 2nd position for 1 byte
    Case "F"
        VINDecode = "Ford"
    Case "M"
        VINDecode = "Mercury"
    Case Else
        VINDecode = "Unknown"
End Select

End Function
[\code]

Good luck,
Glenn
 
One possibility would be Mid$:
Code:
strVIS = "1Y1SK6466MZ071799"
mid$(strVIS,2,2) = "FR"

Hope this helps
Andreas
 
Thanks!
Thanks very much, I tried the code by copying the whole code and adding some more make into it. However, there was not error, but nothing comming out.
 
As written, the function is designed to be used in a formula in the worksheet. For example:
Code:
    A            B
1  VIN         Make
2  1Y1......   =VINDecode(A2)
[\code]
I've tested this several ways and it seems to work just fine.

Glenn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top