Delete All Empty Cells

Поділитися
Вставка
  • Опубліковано 8 лют 2025
  • Delete All Empty Cells.
    This is the code:
    Sub DeleteEmptyCells()
    Dim ws As Worksheet
    Dim lastRow As Long
    Dim col As Range
    Dim cell As Range
    ' Set the worksheet you want to work on
    Set ws = ThisWorkbook.Sheets("Sheet2") ' Change "Sheet1" to your sheet name
    ' Loop through columns A, B, and C
    For Each col In ws.Range("A:C").Columns
    ' Find the last row in each column
    lastRow = ws.Cells(ws.Rows.Count, col.Column).End(xlUp).Row
    ' Loop through each cell in the column from bottom to top
    For Each cell In ws.Range(col.Cells(1, 1), col.Cells(lastRow, 1)).Cells
    ' Check if the cell is empty
    If IsEmpty(cell.Value) Then
    ' Delete the cell and shift up
    cell.Delete Shift:=xlUp
    End If
    Next cell
    Next col
    End Sub

КОМЕНТАРІ •