Delete Entire Row After Finding Name in Array

soulz9

New Member
Joined
Mar 16, 2012
Messages
7
Hello,

I am trying to code the following:

I have supplier names in Column A, and I am searching by the name of the supplier by using the match command, which provides the Row value of the searched name.

Then I would like to delete the supplier that has been found in the array.

So I am using the following code to delete the entire row and shift it up.

Code:
SearchVal = Me.txtSearch.Value
RowVal = Application.Match(CDbl(SearchVal), ws.Range("B:B"), 0) 

 ws.Cells(RowVal, 1).EntireRow.Select
 Selection.Delete Shift:=xlUp
 MsgBox "Item deleted from database"
The 1 in ws.Cells is the Column where the data is found, which is the whole Column A.

I can find the correct name in the array but once I click delete, this error is showing

Run-time error '1004':

Select method of Range class failed

Thank you, anyone please shed some light, will appreciate your efforts.
 
Last edited:
Hi,

Not sure if it will make a difference but just incase it helps - did you already try the method above without Selecting? i.e. replace:

Code:
ws.Cells(RowVal, 1).EntireRow.Select
Selection.Delete Shift:=xlUp
MsgBox "Supplier deleted from database"

with

Code:
ws.Cells(RowVal, 1).EntireRow.Delete Shift:=xlUp
MsgBox "Item deleted from database"
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Re: Delete Entire Row After Finding Name in Array (Resolved)

You just fixed my problem. :eeek: :)

Now I can delete without the error. Its working like a charm.

Thank you

Hi,

Not sure if it will make a difference but just incase it helps - did you already try the method above without Selecting? i.e. replace:

Code:
ws.Cells(RowVal, 1).EntireRow.Select
Selection.Delete Shift:=xlUp
MsgBox "Supplier deleted from database"
with

Code:
ws.Cells(RowVal, 1).EntireRow.Delete Shift:=xlUp
MsgBox "Item deleted from database"
 
Upvote 0
Hi,

Not sure if it will make a difference but just incase it helps - did you already try the method above without Selecting? i.e. replace:

Code:
ws.Cells(RowVal, 1).EntireRow.Select
Selection.Delete Shift:=xlUp
MsgBox "Supplier deleted from database"

with

Code:
ws.Cells(RowVal, 1).EntireRow.Delete Shift:=xlUp
MsgBox "Item deleted from database"


Out of curiosity, do you know what would make the second version work when the first doesn't? It seems like if Excel can delete a selection it should be able to Select it too. Very strange.
 
Upvote 0
Out of curiosity, do you know what would make the second version work when the first doesn't? It seems like if Excel can delete a selection it should be able to Select it too. Very strange.
Hi,

I think if you wanted to use the Select method you need to activate the Sheet first i.e. like this:

Code:
[B][COLOR="DarkRed"]ws.Activate[/COLOR][/B]
ws.Cells(RowVal, 1).EntireRow.Select
Selection.Delete Shift:=xlUp
MsgBox "Supplier deleted from database"

I'm not sure of the actual reason the method requires activation though.
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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