Change code from delete entire row to delete a range of cells in a row

amitcohen

Board Regular
Joined
Jan 14, 2010
Messages
118
Hi Guys
I'm using the following code to delete empty rows
Sub DeleteEmptyRows()
'only if entire row is blank
LastRow = ActiveSheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count
Application.ScreenUpdating = False
For R = LastRow To 1 Step -1
If Application.CountA(Rows(R)) = 0 Then
Rows(R).Delete
End If
Next R
End Sub
But its only works on entire row.

How to change the code so it will delete only first 10 cells that are empty.

In other words, instead of deleting all row no 4 (for instance)
It will only delete "A4:J4".
and on.. and on..

Many thanks for your help.
Amit
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Amit

Is there anything else you want to change?

If the criteria for deletion is that the entire row is empty how will deleting 10 cells make any difference.:)
 
Upvote 0
Try

Code:
Sub DeleteEmptyRows()
Dim LastRow As Long, R As Long
'only if entire row is blank
LastRow = ActiveSheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count
Application.ScreenUpdating = False
For R = LastRow To 1 Step -1
    If Application.CountA(Range("A" & R).Resize(, 10)) = 0 Then
        Range("A" & R).Resize(, 10).Delete shift:=xlShiftUp
    End If
Next R
End Sub
 
Upvote 0
Hi Norie

I see your point here :eek:

Its just a code I used in other file, now in a need to use same concept
in a new file where columns 10 (J) and higher are in use..
and cannot be deleted.

Sorry for not making myself clear on that issue.
 
Upvote 0

Forum statistics

Threads
1,215,161
Messages
6,123,375
Members
449,098
Latest member
Jabe

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