Eliminate Blank cells and Move up Data Code

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,486
In My Range G20:G32 I Have:

Excel 2010
G
20 Able
21 Bob
22
23 Cathy
24
25 Daryl
26 Edward
27 Fred
28
29 Marvin
30
31
32 Pete

<colgroup><col style="width: 25pxpx"><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

<tbody>
</tbody>

This code is not working - Can someone REPAIR my FAULTY LOGIC?

Code:
Sub EliminateBlankRows()
LR = Range("G" & Rows.Count).End(xlUp).Row
Set Rng = Range("G20:G" & LR)
Application.Calculation = xlCalculationManual
With Rng
    For i = LR To Rng(1).Row + 1 Step -1
        If Cells(i, 7).Value = "" Or Cells(i, 7).Offset(-1).Value = "" Then
            Application.CutCopyMode = False
            Cells(i, 7).Cut Destination:=Cells(i, 7).Offset(-1, 0)
            i = i - 1
        Else
'        j = j - 1
'        i = i + j
        End If
    Next i
End With
Application.Calculation = xlCalculationAutomatic
End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try
Code:
Sub delblank()
Dim lr As Long
lr = Cells(Rows.Count, "G").End(xlUp).Row

For i = lr To 20 Step -1
    If Cells(i, "G") = "" Then Cells(i, "G").Delete Shift:=xlUp
Next i
End Sub
 
Upvote 0
Another way
Code:
Sub jim_may()
   Range("G20:G32").SpecialCells(xlBlanks).Delete xlUp
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,560
Messages
6,114,306
Members
448,564
Latest member
ED38

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