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!
 

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.
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
 
Upvote 0
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:
 
Upvote 0

Forum statistics

Threads
1,215,020
Messages
6,122,712
Members
449,093
Latest member
Mnur

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