VBA - How to use VLookup with Letters and Numbers to Delete Rows?

GBGPneus

New Member
Joined
Feb 7, 2017
Messages
4
Hello! I'm really struggling with this issue using VBA in Excel. For starters, I'm no expert in Excel, but I'm trying my best with a really complex issue applying VLookup. I'll detail the issue with images below:


  • I have a table that associates code letters to numbers in a separate sheet. I did that because I need a method to quantify these letters so I may later compare them. They do not work in alphabetical order.


f8bfde32349f4c5793ca9fe9b81ed305.png



  • With this table (In the separate sheet), I intend to allow the user to insert a table with many "products" that have a code assigned to them (the codes are composed of a combination of numbers and letters. Ex: 91V). Then, the user will run a macro and insert a new code. The inserted code will be used by the macro do compare with the other codes in the table and any given row with a code composed by larger numbers than the onde input by the user or a letter with a lower value, will be deleted. Example of a table inserted by the user:


a8daa70a2b5440deaef1be6ddc5318ff.png




This is what I have until now. However, all it does is look for a letter in my separate sheet and turn it into a value and delete any rows that have a number lower than the letter's value. Its not at all what I want.

Code:
<code style="white-space: inherit; margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif;">[COLOR=#101094]Sub[/COLOR][COLOR=#303336] DeletarIndices[/COLOR][COLOR=#303336]()[/COLOR][COLOR=#303336]

indice [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] InputBox[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Digite o Valor Desejado"[/COLOR][COLOR=#303336],[/COLOR][COLOR=#7D2727]"Teste"[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]

[/COLOR][COLOR=#101094]Set[/COLOR][COLOR=#303336] planilhaV [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] Sheets[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"IV"[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]Dim[/COLOR][COLOR=#303336] vValores [/COLOR][COLOR=#101094]As[/COLOR][COLOR=#101094]String[/COLOR][COLOR=#303336]
sResult [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] Application[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]VLookup[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]indice[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] planilhaV[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Range[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"A2:B11"[/COLOR][COLOR=#303336]),[/COLOR][COLOR=#7D2727]2[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]

Application[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]ScreenUpdating [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]False[/COLOR][COLOR=#303336]
Application[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Calculation [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] xlCalculationManual
[/COLOR][COLOR=#101094]Dim[/COLOR][COLOR=#303336] i [/COLOR][COLOR=#101094]As[/COLOR][COLOR=#101094]Long[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]For[/COLOR][COLOR=#303336] i [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] Range[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"A"[/COLOR][COLOR=#303336]&[/COLOR][COLOR=#303336] Rows[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Count[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]xlUp[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]Row [/COLOR][COLOR=#101094]To[/COLOR][COLOR=#7D2727]1[/COLOR][COLOR=#101094]Step[/COLOR][COLOR=#303336]-[/COLOR][COLOR=#7D2727]1[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]If[/COLOR][COLOR=#101094]Not[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]Range[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"A"[/COLOR][COLOR=#303336]&[/COLOR][COLOR=#303336] i[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]Value [/COLOR][COLOR=#303336]>[/COLOR][COLOR=#303336] sResult[/COLOR][COLOR=#303336])[/COLOR][COLOR=#101094]Then[/COLOR][COLOR=#303336]
Range[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"A"[/COLOR][COLOR=#303336]&[/COLOR][COLOR=#303336] i[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]EntireRow[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Delete
[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]If[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]Next[/COLOR][COLOR=#303336] i
Application[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Calculation [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] xlCalculationAutomatic
Application[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]ScreenUpdating [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]True[/COLOR][COLOR=#303336]

[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]Sub[/COLOR]</code>

I appreciate any help. :)
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,215,064
Messages
6,122,939
Members
449,094
Latest member
teemeren

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