Delete row if bellow/lower/under cells have value matches [VBA]

tocy777

New Member
Joined
Oct 28, 2015
Messages
33
So I have this table, my goal is to remove the ones that are bold. The logic is to remove the rows which contain additional FALSE value, so I would end up with a FALSE, TRUE, FALSE, TRUE row.

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]False[/TD]
[/TR]
[TR]
[TD]True[/TD]
[/TR]
[TR]
[TD]False[/TD]
[/TR]
[TR]
[TD]False[/TD]
[/TR]
[TR]
[TD]False[/TD]
[/TR]
[TR]
[TD]True[/TD]
[/TR]
</tbody>[/TABLE]


Why?

I am scraping a site which has this annoying little html gimmick where the table is actually in a list format so when I paste it into Excel it looks like this, in the second column I am using the formula ISNUMBER:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Apple[/TD]
[TD]FALSE[/TD]
[/TR]
[TR]
[TD]2.07[/TD]
[TD]TRUE[/TD]
[/TR]
[TR]
[TD]Microsoft[/TD]
[TD]FALSE[/TD]
[/TR]
[TR]
[TD]USA[/TD]
[TD]FALSE[/TD]
[/TR]
[TR]
[TD]IT[/TD]
[TD]FALSE[/TD]
[/TR]
[TR]
[TD]1.42[/TD]
[TD]TRUE[/TD]
[/TR]
</tbody>[/TABLE]

I want the bold lines to be gone, so I would end up with a company name and a value.

I have been trying but couldn't come up with a real solution, I am also open to a VBA approach!

Thanks in advance!
 
Last edited:

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Assuming that your data starts on row 2, enter this formula in C3 and copy down:
Code:
=IF(B2=FALSE,C1+1,0)
Then you can use Filters and filter out any values greater than 1.

Note: If your data starts in row 1, just enter a 1 if row 1 is FALSE, else enter a zero.

If you want to actually delete instead of filtering the data, you can used Advanced Filters to filter to a new location, or use VBA (that's is the approach I would probably take).
 
Last edited:
Upvote 0
Here is a VBA solution. You don't need the helper column B to use this:
Code:
Sub MyDeleteRows()

    Dim lastRow As Long
    Dim myRow As Long
    
    Application.ScreenUpdating = False
    
'   Find last row with data in column A
    lastRow = Cells(Rows.Count, "A").End(xlUp).Row
    
'   Loop through all rows
    For myRow = lastRow To 2 Step -1
        If Not (IsNumeric(Cells(myRow, "A"))) And Not (IsNumeric(Cells(myRow - 1, "A"))) Then
            Rows(myRow).Delete
        End If
    Next myRow
    
    Application.ScreenUpdating = True
    
End Sub
 
Last edited:
Upvote 0
I am beyond grateful! You saved me some very precious time and brain cells, I hope I can repay you some day in some shape or form!
 
Upvote 0
You are welcome!

hope I can repay you some day in some shape or form!
Just "pay it forward", in any way you can!
 
Upvote 0
Using a completely different method, I believe this macro will also do what you asked for in case you might want to consider it...
Code:
[table="width: 500"]
[tr]
	[td]Sub KeepNumbersAndFirstNonNumbers()
  Dim Ar As Range
  Application.ScreenUpdating = False
  For Each Ar In Columns("A").SpecialCells(xlConstants, xlTextValues).Areas
    If Ar.Count > 1 Then Ar.Offset(1).Resize(Ar.Count - 1).EntireRow.Delete
  Next
  Application.ScreenUpdating = True
End Sub
[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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