Livin404
Well-known Member
- Joined
- Jan 7, 2019
- Messages
- 774
- Office Version
- 365
- 2019
- Platform
- Windows
Greetings,
I put the workbook in the Dropbox, the best way to capture the full picture. I changed the table to names, These names are random as I change the text data. I provided some random mission numbers with a couple of notes. It is picking up "Most" of the codes, but it is missing a few. Of course I get the mismatch error. If you look at the first Column you will see there are single digits, double digits. I know the I am going to have an issue of VLOOKup going to the first digit beginning with the same letter. It is also not recognizing double digit numbers. Maybe Match would work better, but I have no experience with Match.
Find Mission change.xlsm
Thank you,
I put the workbook in the Dropbox, the best way to capture the full picture. I changed the table to names, These names are random as I change the text data. I provided some random mission numbers with a couple of notes. It is picking up "Most" of the codes, but it is missing a few. Of course I get the mismatch error. If you look at the first Column you will see there are single digits, double digits. I know the I am going to have an issue of VLOOKup going to the first digit beginning with the same letter. It is also not recognizing double digit numbers. Maybe Match would work better, but I have no experience with Match.
Find Mission change.xlsm
VBA Code:
Sub VLOOK_UP()
Dim alphaCode As String, n As Variant
With Worksheets("MSN Decoder")
alphaCode = .Range("K6").Value
n = Mid(alphaCode, 4, 2) ''' extracts the 4th and 5th characters
''' If one character is a letter and the other is a number then choose single character
''' otherwise choose double characters
If IsNumeric(Left(n, 1)) And Not IsNumeric(Right(n, 1)) Then
n = Left(n, 1)
ElseIf Not IsNumeric(Left(n, 1)) And IsNumeric(Right(n, 1)) Then
n = Left(n, 1)
End If
''' Paste/insert the output value
.Range("H10").Value = Application.WorksheetFunction.VLookup(n, Worksheets("Operator").Range("A:B"), 2, 0)
End With
End Sub
Thank you,