How to Delete Queues with User Code?

Asked

Viewed 28 times

0

A little while ago I did this question who has not received any answers:

But I got some help from some people and I was able to evolve the code to a certain extent.

My code is now 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", "GBG Pneus"))   ' 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 a help to adapt this code with an increment. I need to allow the user to enter not just a letter, but a code (Ex: 91T). To finish, I need that when inserting the example "91T", the code excludes from the table all lines that include Minor Letters and Larger Numbers.

  • I removed the text from the other question once you linked it to this one, which makes its text unnecessary on this one.

  • Okay! Sorry! I’m new here!

  • This question seems to me the same as the previous one. You "evolved" the problem, but the doubt remains the same, no?

  • The ultimate goal remains the same, but I’ve gone through major code changes. Suddenly with what I have now someone can give only the final piece.

  • Well, if the goal is the same, you should not open two questions. You could have edited that. This site is not a forum. If you haven’t done it yet, do the [tour] and mainly read [Ask]. I’m going to vote to close this as a duplicate of that, okay? Try to get better there so we can help you. :)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.