Delete Empty Cells in excel 2007 and Shift Left

rbrown8432

New Member
Joined
Nov 9, 2011
Messages
3
How would I delete empty cells and shift remaining data to the left in excel 2007 for multiple fields? Example: If data range starts in C1 and ends in T2686
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try this..

Sub DeleteEmptyCells()

Dim MyRange As Range
Dim FinalRow As Long

FinalRow = Cells(Rows.Count, 3).End(xlUp).Row
Set MyRange = Range("C1:T" & FinalRow)

MyRange.SpecialCells(xlBlanks).Delete shift:=xlToLeft

End Sub
 
Upvote 0
I opened excel, hit Alt F11, chose, This Workbook, and pasted the code into the script editor. Chose tools, macro, then run and nothing happened.

Thanks
 
Upvote 0
hmmm works on my end...

In the project pane, right click the name of your book, and click insert module, and paste the code there. Also, keep in mind, the macro's range is column C through T as you indicated above...you would have to change MyRange in the code to reference different ranges.
 
Upvote 0
Than you. I saved the file as a csv formate and opened it in a notepad. It revealed that there were commas. That is the reason it would not identify the empty cell as EMPTY. Seems a little elementary however I used the find and replace all feature and chose the multiple commas in exchange for a comma. it replaced them and shifted all the data.
 
Upvote 0

Forum statistics

Threads
1,203,051
Messages
6,053,220
Members
444,648
Latest member
sinkuan85

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