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

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
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,214,924
Messages
6,122,294
Members
449,077
Latest member
Rkmenon

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