Find row number with VLookUp (VBA)

PhilC999

New Member
Joined
Oct 19, 2007
Messages
42
Hi all,

Code:
    Item = Val(ItemNo.Caption)
    Description = Application.WorksheetFunction.VLookup(Item, _
                    wParts.Range("$B$2:$B" & LastRW), 1, False)

I have the above code which successfully looks up a unique value in the range on the wParts worksheet. However, the row which the value appears on then has to be deleted. Is there a way to discover the row on which the value was found?

Phil
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi Phil

Why don't you use the VBA Find() method to return a reference to the actual found cell or maybe Application.Match to locate the row instead of Vlookup?
 
Upvote 0
Hi Richard,

Thanks for the quick reply. I've just had a quick search for both the methods you suggested but nothing seems immediately apparent. Would it be possible to for you to give a quick example of the FIND() method?

Phil
 
Upvote 0
Sure:

Code:
Dim rFound As Range
With wParts.Range("$B$2:$B" & LastRW)
  Set rFound = .Find(What:=ItemNo.Caption, After:=.Range("A1"))
End With
'Test if value found:
If Not rFound Is Nothing Then 'if it's not nothing then it's something ie it was found
  rFound.EntireRow.Delete 'deletes the value and the entire row
End If
 
Upvote 0

Forum statistics

Threads
1,226,449
Messages
6,191,105
Members
453,639
Latest member
coding123456

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