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.

False
True
False
False
False
True

<tbody>
</tbody>


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:

AppleFALSE
2.07TRUE
MicrosoftFALSE
USAFALSE
ITFALSE
1.42TRUE

<tbody>
</tbody>

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

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
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,215,268
Messages
6,123,970
Members
449,137
Latest member
yeti1016

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