Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete blank cells in range

Tags:

excel

vba

cell

I want to delete blank cells in a range (E1:E130).

This code skips cells.

For Each cell In ranger
    If cell.Value = "" Then
        cell.Delete
    End If
next cell

To make my objective more clear: I have a list of cells with text and empty cells in the range E1:E130 and I want to make a list starting on E1 without any empty cells.
Sorting on alphabet for instance would also be a good solution, however that didn't work out for me either.

like image 208
Boolean Avatar asked Sep 13 '25 01:09

Boolean


2 Answers

I'd go like follows

With Range("E1:E130")
    If WorksheetFunction.CountA(.Cells) > 0 Then .SpecialCells(xlCellTypeBlanks).Delete Shift:=xlShiftUp
End With
like image 187
DisplayName Avatar answered Sep 14 '25 15:09

DisplayName


You could use the Range.SpecialCells Method to delete all blank cells in a specific range at once:

Range("E1:E130").SpecialCells(xlCellTypeBlanks).Delete
like image 21
Pᴇʜ Avatar answered Sep 14 '25 16:09

Pᴇʜ