Delete Rows IF criteria - Need VBA Help

unit213

Active Member
Joined
Jul 11, 2003
Messages
427
I need to delete rows if there are blank cells in column A. I also need conditional formatting removed from those rows. Does anyone know a VBA solution?

TIA,

Dan
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
do you mean you want to clear the contents of the row where cell A is blank, or do you mean completely delete the row so that for example row 5 becomes row 4 when 4 is deleted? if you mean clear contents, this will work

Code:
Sub test()
Dim LastRow As Long
LastRow = [A65536].End(xlUp).Row
For i = 1 To LastRow
If Cells(i, 1) = "" Then
    With Rows(i & ":" & i).EntireRow
        .ClearContents
        .FormatConditions.Delete
    End With
End If
Next i
End Sub

otherwise, to delete the row use this:

Code:
Sub test()
Dim LastRow As Long
LastRow = [A65536].End(xlUp).Row
For i = LastRow To 1 Step -1
If Cells(i, 1) = "" Then Rows(i & ":" & i).EntireRow.Delete
Next i
End Sub

if you use the second code, there would be no need to delete the conditional formatting in a row that no longer exists


hth
kevin
 
Upvote 0
Very useful for me too! How could I add to this code to delete rows IF cell in Column A does NOT include a given character, in this case "@" (ie. first delete rows where cells in Column A are blank, then delete those where "@" is missing?

Am tempted to use Worksheet.Function.Insnumber method [If(Isnumber(Search("@".. )] is what I use in Excel to perform this operation) but cannot get synthax right.

Any help hugely appreciated!

olivier
 
Upvote 0

Forum statistics

Threads
1,223,636
Messages
6,173,485
Members
452,516
Latest member
archcalx

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