Delete rows without data except in column A

dstepan

Board Regular
Joined
Apr 16, 2009
Messages
160
I have a report that lists data in column A and then "X"s in columns B-F.

I want to delete the rows which do not have an "X".

What is the easiest way to do this? Macro? VBA? I'm a real beginner with VBA.

For example:

This is what I have now...
A B C D E F
1 Tom X
2 Sally
3 Mike X X
4 Jim X

This is what I want....
1 Tom X
2 Mike X X
3. Jim X
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Maybe a macro like this

1. Press Alt+F11 to open the Visual Basic Editor
2. Select Insert from the toolbar and then Module
3. Paste this code in there
Code:
Sub Deletedata()
    Dim I As Integer
    Dim wf As WorksheetFunction
    Set wf = Application.WorksheetFunction
    For I = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
        If wf.CountIf(Range("B" & I & ":" & "F" & I), "x") = 0 Then
            Rows(I).EntireRow.Delete
        End If
    Next I
End Sub

Please create a copy of your data/sheet before running the code
 
Upvote 0
The code works but it deleted my title row. I guess I should've shown that in my example.
How can I change the code to ignore row 1?
 
Upvote 0
change
Rich (BB code):
For I = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
to
Rich (BB code):
 For I = Range("E" & Rows.Count).End(xlUp).Row To 2 Step -1
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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