Delete entire row if cell value is equal to

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,422
Office Version
  1. 2016
Platform
  1. Windows
Can someone show me how to delete an entire row if a Cell.Offset value is equal to a specific value?

I have this so far but don't know what else I need to specify the row number;

Code:
If cell.Offset(0, 10).Value = "Archived" Then
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try:
Code:
If cell.Offset(0, 10).Value = "Archived" Then Rows(cell.Row).Delete
 
Upvote 0
An alternative syntax is
Rich (BB code):
If cell.Offset(0, 10).Value = "Archived" Then cell.EntireRow.Delete
 
Last edited:
Upvote 0
I'd like to make an observation to the OP. Your use of the variable Cell would seem to suggest that you are running a For..Each loop to iterate the cells in some (unspecified) columnar range. If it is possible for the word "Archived" to appear in two (or more) adjoining rows in that offsetted column, then you will not get the correct row deletions. For..Each iterations of cells in such a range takes place from a lower row number to a higher row number. Because of this, if you delete a row, the next row moves up to fill that deleted row's spot, but the loop has already processed that cell so it will move on to the next cell which means the row that moved up will not be checked to see if its offsetted cell contains the word "Archived" or not. The only way to run a loop where rows will be deleted and adjacent rows could meet the criteria for deletion is to iterate the loop backwards from the higher row number down to the lower row number.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,307
Members
452,633
Latest member
DougMo

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