Hello! I'm experiencing great difficulty with a problem using VLookup in Excel VBA. First of all, I am not VBA expert but I have been able to use VLookup but I am not having the effect I would like. I will explain below with more detail the situation with images:
Could you help me?
EDIT:
On request, this was the code I had until then. However, it was a work in process that logically is nowhere near what I need.
Sub DeletarIndices()
indice = InputBox("Digite o Valor Desejado", "Teste")
Set planilhaV = Sheets("IV")
Dim vValores As String
sResult = Application.VLookup(indice, planilhaV.Range("A2:B11"), 2)
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim i As Long
For i = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
If Not (Range("A" & i).Value > sResult) Then
Range("A" & i).EntireRow.Delete
End If
Next i
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
EDIT 2
My code now looks like this:
Option Explicit
Sub DeletarIndices()
Dim indice As String ' To hold our user input letter
Dim indiceValue As Long ' To hold the numeric value of our user input letter
Dim rowLetter As String ' To hold the current row letter
Dim rowLetterValue As Long ' To hold the numeric value of the current row letter
Dim firstRow As Long ' First row of your data
Dim lastRow As Long ' Last row of your data
Dim currentRow As Long ' Current row for your loop counter
Dim sht As Worksheet ' To hold the worksheet you're working on
Dim planilhaV As Worksheet ' To hold your lookup worksheet
Set sht = ThisWorkbook.Worksheets("Plan1") ' Use the name of your worksheet
Set planilhaV = ThisWorkbook.Worksheets("IV") ' As in your original example
firstRow = 1
lastRow = sht.Range("A" & Rows.Count).End(xlUp).Row
indice = UCase(InputBox("Digite o IC/IV Desejado", "Teste")) ' Convert user input to upper case and store
indiceValue = CLng(Application.VLookup(indice, planilhaV.Range("A2:B11"), 2, False)) ' Creating numeric indice value with lookup table
For currentRow = lastRow To firstRow Step -1
rowLetter = UCase(Right(sht.Range("A" & currentRow).Value, 1)) ' Get letter from code in column A, converted to upper case
rowLetterValue = CLng(Application.VLookup(rowLetter, planilhaV.Range("A2:B11"), 2, False)) ' Creating numeric value for current row letter with lookup table
If rowLetterValue < indiceValue Then ' Compare the numeric letter values, and if smaller than user input...
sht.Rows(currentRow).EntireRow.Delete ' Delete the row
End If
Next currentRow
End Sub
Now I would just need some help to adapt this code with an increment. I need to allow the user to insert not only a letter, but a code (Ex: 91T). To finish, I need to insert the example "91T", the code excludes from the table all the lines that include Minor Letters and Bigger Numbers.