PDA

View Full Version : Delete Specific Rows



Prema
08-13-2010, 12:44 AM
Hi again,

I would greatly appreciate if members can assist me with the below issue.

I am trying to delete all the (entire) rows from all worksheets In all workbooks in a folder based on a specific cell value.

I managed to find all the cells with specific value and also entire row addresses of all the selected cells and then I am deleting the rows.

But while doing so if that specific value exists in two different cells of one row, then the code will delete the row twice (First it will delete the row with specific cell value and also it will delete the row below the specific cell value).

But I want delete only that specific row that contains cell OR cells with specific value.

How can I modify this. ?

Any and all assistance is highly appreciated.

I can forward the code if you need more info on this.

Thanks in advance,
Prema

Bob Phillips
08-13-2010, 01:45 AM
Show us your code.

Prema
08-13-2010, 05:06 AM
Thanks for the prompt reply.

Below is the code to delete rows based on specific cell value.



Private Sub DeleteSpecificRows()
Dim DeleteRows() As String
Dim XI As Long
Dim rcell As Range
Dim rcells As Range
Dim DeletedRows As Integer


'Here we will find the cells with specific value
For Each rcell In rcells.Cells
XI = XI + 1
ReDim Preserve DeleteRows(XI)
DeleteRows(XI) = rcell.EntireRow.Address
Next rcell

For XI = UBound(DeleteRows) To 1 Step -1
Range(DeleteRows(XI)).EntireRow.Delete
DeletedRows = DeletedRows + 1
Next XI
End Sub


Please let me know how do I modify this?

Thanks again,
Prema

Aussiebear
08-13-2010, 05:36 PM
Do you know which column the value is likely to be in ?

Prema
08-15-2010, 10:06 PM
I want to delete only the rows that contain this specific value irrespective of the column's position/(s).

Thanks,