Help with if statements!

CC268

Active Member
Joined
Mar 7, 2016
Messages
326
This is driving me a bit nuts...seems like this should be really easy so I am trying to figure out the code on my own here.

I want to use the .Clear command to simply Clear a row if there are NO VALUES in columns A through I (there will be values in J and K that I want cleared if the condition that there are no values in A through I are met).

ABCDEFGHIJK
safsdsfsdsfsd
sdfssdfs
sdsdsdsdsdsd
sdsdsdsd
sdsdsdssdsd

<tbody>
</tbody>

So I wrote a bunch of mumbo jumbo above - but you can see that I want to CLEAR the contents of rows 2 and 4 because those rows do not contain any values in columns A through I.

Is this a lot harder to do than I think it should be?
 

Some videos you may like

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Steve_R

Active Member
Joined
Oct 28, 2015
Messages
350
Do you mean you wish to delete rows that are blank in all cells in columns A-I? If so, the following macro will do it

Code:
Sub DeleteBlankRows()

lRow = ActiveSheet.UsedRange.Count

Application.ScreenUpdating = False
For i = lRow To 2 Step -1
   
    If Application.WorksheetFunction.CountA(Range("A" & i & ":I" & i)) = 0 Then 'if everything blank 
        Rows(i).Delete
    End If
Next
Application.ScreenUpdating = True
End Sub

If you don't know how to use a macro
(with the required sheet open)
1) use keystroke combination [Alt]/[F11]
2) Create a new regular module using keystroke combination [Alt]//[M]
3) Paste the code
4) Press F5 to run the code

Make sure you test on a copy first.

EDIT: Alternatively, use a multi-colunm sort to get blank rows into a block and manually delete the blank rows.
 
Last edited:

CC268

Active Member
Joined
Mar 7, 2016
Messages
326
Thanks a lot I will try this when I am at work tomorrow! I didn't think about doing a multi column sort but that probably would have been very easy lol...
 

Watch MrExcel Video

Forum statistics

Threads
1,122,548
Messages
5,596,791
Members
414,103
Latest member
imamalidadashzada

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
Top