Delete Blank Cells and shift cells up code not working

bobbyexcel

Board Regular
Joined
Nov 21, 2019
Messages
88
Office Version
  1. 365
Platform
  1. Windows
Can you please help me on the below code to Delete Blank Cells and shift cells up.

Tried the below 2 but not working.. I still have blank cells which are not getting deleted.

Columns("F").SpecialCells(xlCellTypeBlanks).Delete shift:=xlUp

With Range("A:J") ' & Lastrow2)
If WorksheetFunction.CountA(.Cells) > 0 Then .SpecialCells(xlCellTypeBlanks).Delete shift:=xlShiftUp
End With
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Can you please check one of the lines that is not being deleted, to see if it is truly blank. 2 tests as follows:

=ISBLANK(A1)
=LEN(A1)

Please amend cell reference as necessary and please report back on the results.
 
Upvote 0
thanks for the heads-up.

ISBLANK result is coming as False but Length is zero.
 
Upvote 0
Ok that implies that these cells hold nullstrings. The SpecialCells method will not work. Instead you need to loop through your rows, from bottom to top and then delete the rows based on whether or not the values have zero character length.

Are you OK with that or do you need help?
 
Upvote 0
If you have copy/pasted as values the data try
VBA Code:
With Range("F2", Range("F" & Rows.Count).End(xlUp))
   .Value = .Value
   .SpecialCells(xlCellTypeBlanks).Delete shift:=xlUp
End With
 
Upvote 0
It's something I picked up, from a thread on here, some years ago.
 
Upvote 0
Yes it worked very well. Thanks for your help. .You saved my day..


If you have copy/pasted as values the data try
VBA Code:
With Range("F2", Range("F" & Rows.Count).End(xlUp))
   .Value = .Value
   .SpecialCells(xlCellTypeBlanks).Delete shift:=xlUp
End With
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,981
Messages
6,175,768
Members
452,668
Latest member
mrider123

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