Eliminate empty rows and shift not empty rows on the left

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
526
Office Version
  1. 2007
Hello everybody.

In the range A1:J10 I have a situation like this

https://imgur.com/ukRGiNG

I need to eliminate the empty rows (3, 4, 6 e 9) end shift the not empty rows on the left, so that no empty cells

https://imgur.com/a/tXxE4rc

I have tried something like this to eliminate the rows with a check on column F, but I am not convinced about.

Code:
                    Dim ic As Variant
                    Dim ir As Long
                    Dim x As Long
                        ic = 6 
                        ir = 1
                            For x = 1 To 10
                                    If Cells(ir, ic) = Empty Then
                                        Cells(ir, ic).EntireRow.Delete
                                    End If
                                ir = ir + 1
                                x = x + 1
                            Next
 
Last edited:

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.
If your sample data is representative, then give this a try in a copy of your workbook
Code:
Sub Eliminate_Blanks()
  Application.ScreenUpdating = False
  On Error Resume Next
  Range("A1", Cells.SpecialCells(xlLastCell)).SpecialCells(xlBlanks).Delete Shift:=xlToLeft
  Columns("A").SpecialCells(xlBlanks).EntireRow.Delete
  On Error GoTo 0
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
If your sample data is representative, then give this a try in a copy of your workbook
Code:
Sub Eliminate_Blanks()
  Application.ScreenUpdating = False
  On Error Resume Next
  Range("A1", Cells.SpecialCells(xlLastCell)).SpecialCells(xlBlanks).Delete Shift:=xlToLeft
  Columns("A").SpecialCells(xlBlanks).EntireRow.Delete
  On Error GoTo 0
  Application.ScreenUpdating = True
End Sub

Perfect, it works fine.

Thank's.
 
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