Macro to Delete Empty Cells -> Shift Left

sthrncaliguy

Board Regular
Joined
Jul 28, 2009
Messages
213
I am in need of a macro that will look through a pre set range of cells, say B:B for example, and for each cell that is blank, it will delete and shift cells left.

I know this is probably simple, just need some help with the code.

Thanks!
 

Some videos you may like

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

id107

Well-known Member
Joined
Apr 16, 2008
Messages
578
this should do it.
Code:
Sub test()
 
    Dim i As Long, LastRow As Long
 
    LastRow = Cells(Rows.Count, "B").End(xlUp).Row
 
    For i = 1 To LastRow
        If Range("B" & i).Value = "" Then
            Range("B" & i).Delete Shift:=xlToLeft
        End If
    Next i
 
End Sub
 

john456852

New Member
Joined
Aug 22, 2012
Messages
2
this should do it.
Code:
Sub test()
 
    Dim i As Long, LastRow As Long
 
    LastRow = Cells(Rows.Count, "B").End(xlUp).Row
 
    For i = 1 To LastRow
        If Range("B" & i).Value = "" Then
            Range("B" & i).Delete Shift:=xlToLeft
        End If
    Next i
 
End Sub


How to Shift Cells Up? Do u use xlToUp or xlUP?
:p:ROFLMAO::confused:
 

Watch MrExcel Video

Forum statistics

Threads
1,127,334
Messages
5,624,069
Members
416,010
Latest member
NJT

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