Deleting Contents of Empy Cells with Macro

TooZippy

Board Regular
Joined
Dec 30, 2018
Messages
70
Hi,

I am using this Macro and it does not do exactly what I want. It deletes the contents of the cells that I highlight but not the cells that are not highlighted in a column even though all of those cells have a null value in them. I want it to go through all of the rows in a column and delete the contents of the cells that have a null value in them that appear empty. Can anybody help please?

Thank you,

Jared Z.

Code:
Sub clear_empty_cell()
   
   Application.ScreenUpdating = False
   Dim cell As Range
      
     ActiveSheet.UsedRange.Replace What:=Chr(160), Replacement:=Chr(32), _
     LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
   On Error Resume Next   'in case no text cells in selection
   For Each cell In Intersect(Selection, Selection.SpecialCells(xlConstants, xlTextValues))
     cell.Value = Application.Trim(cell.Value)
   Next cell
   On Error GoTo 0
   Application.ScreenUpdating = True
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try this

Code:
Sub clear_empty_cell()
   
    Application.ScreenUpdating = False
    Dim cell As Range
    
    ActiveSheet.Cells.Replace What:=Chr(160), Replacement:=Chr(32), _
        LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
    On Error Resume Next   'in case no text cells in selection
    For Each cell In ActiveSheet.Cells.SpecialCells(xlConstants, xlTextValues)
        cell.Value = Application.Trim(cell.Value)
    Next cell
    On Error GoTo 0
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank you. I will give a try later on today and post a reply to let you know if it works or not.

JZ
 
Upvote 0
Dante,

I tried your Macro this morning and it works great! Thank you for responding to my thread.

Jared Z.
 
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,616
Members
452,661
Latest member
Nonhle

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