vba code to search through list

panexel

New Member
Joined
Feb 15, 2011
Messages
2
Hi,
I need to search through a list of part number matching a value. At the moment the code I have is not really efficient as it goes through the entire list of part numbers using a for loop. This takes a long time.

Is there a equivalent vba code to 'find' option, if so can I have some help with it.

After I find the matching part number in list 2 I need to delete it off or carry out another calculation. (following bit of code below shows a portion I have done to delete the entire line if a matching part number is found.)

SCount = Sheets("Specials").Range("A70000").End(xlUp).Row

For x = SCount To 2 Step -1
key = Sheets("Specials").Cells(x, "A").Value
For i = BCount To 2 Step -1
keyb = Sheets("Latest B").Cells(i, "C").Value
Application.StatusBar = "looking for Specials PN: " & key & " in Latest B PN: " & keyb
If key = keyb Then
Sheets("Latest B").Rows(i).EntireRow.Delete
End If
Next i
Next x

Thank you for all your help in advance.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi panexel,

There is a "Find" function in VBA that you could use, but first, is there any chance the value you are searching for exists more than once in the list you are searching?.

Regards

ColinKJ
 
Upvote 0
Hi ColinKJ
Thank you for your response.
There could be the possibility of it appearing more than once but highly unlikely. I will try to lookup on the syntax for the find function. It would be great if you could also help me on it.
Cheers!
panexel
 
Upvote 0
Hi panexel,

Try this code, it's not tested, but see how it goes:

Code:
SCount = Sheets("Specials").Range("A70000").End(xlUp).Row
For x = SCount To 2 Step -1
    key = Sheets("Specials").Cells(x, "A").Value
    c = 0
    On Error Resume Next
    c = Sheets("Latest B").Columns("C:C").Find(What:=key, LookIn:=xlValues).Row
    g = Err
    On Error GoTo 0
    If IsNumeric(c) = False Or g = 91 Or c = 0 Then GoTo nextx
    Sheets("Latest B").Rows(c).EntireRow.Delete
nextx:
Next x

Regards

Colin
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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