ClearContents of blank cells in a Table Column

adambc

Active Member
Joined
Jan 13, 2020
Messages
368
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I have a Table/Column which contains blank cells as a result of an IF formula eg =IF(x=y, z, "") - but of course the cell is not "really" blank (it still contains the formula)!

I either need a way to make the IF formula make the cell truly blank, or a way to go through the Column (ideally by Column Name) and ClearContents ...

I'm currently doing this by filtering on Blanks, then deleting using the following code - but it is VERY slow ...

VBA Code:
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=36, Criteria1:="="
    ActiveSheet.ListObjects("Table1").ListColumns("DateCompleted").DataBodyRange.Select
    Selection.ClearContents
    ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=36

Can anyone suggest an alternative/more efficient way to do this please?

Thanks ...
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Don't understand why you need to clear those cells; however I an sure that if you add Application.Calculation = xlCalculationManual before your code and Application.Calculation = xlCalculationAutomatic at the end it will be much faster
 
Upvote 0
make the IF formula make the cell truly blank
That is not possible, because the main concept of Excel is that it returns a value for a formula
a way to go through the Column (ideally by Column Name) and ClearContents

Try this code and rename the Table Name "TableX" and Column Name "[Col 2]":
VBA Code:
Sub ClearBlanksInTableColumn()
   Dim CellX As Range, r As Range
   Set r = Range("TableX[Col 2]")
   r.Select
   For Each CellX In r.Cells
      If CellX.Value2 = "" Then CellX.ClearContents
   Next CellX
End Sub

Here is an example table with data for the code above:
Book1.xlsm
AB
1TableX
2Col 1Col 2
3wefgh 
4sedfrg 
5edrfgv 
6wsedrf 
7wsedrf 
8e34rtgzhb 
9asdfblablabla
10okjhgt 
11poiuzgb 
12thnbg 
13 
14sadiofv 
Sheet23
Cell Formulas
RangeFormula
B3:B14B3=IF(A3="asdf","blablabla","")
 
Upvote 0
Solution
That is not possible, because the main concept of Excel is that it returns a value for a formula


Try this code and rename the Table Name "TableX" and Column Name "[Col 2]":
VBA Code:
Sub ClearBlanksInTableColumn()
   Dim CellX As Range, r As Range
   Set r = Range("TableX[Col 2]")
   r.Select
   For Each CellX In r.Cells
      If CellX.Value2 = "" Then CellX.ClearContents
   Next CellX
End Sub

Here is an example table with data for the code above:
Book1.xlsm
AB
1TableX
2Col 1Col 2
3wefgh 
4sedfrg 
5edrfgv 
6wsedrf 
7wsedrf 
8e34rtgzhb 
9asdfblablabla
10okjhgt 
11poiuzgb 
12thnbg 
13 
14sadiofv 
Sheet23
Cell Formulas
RangeFormula
B3:B14B3=IF(A3="asdf","blablabla","")
@PeteWright

Duh, should have worked that out for myself!!!

Perfect, thank you ...
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,706
Members
449,048
Latest member
81jamesacct

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