VBA code to clear contents of all cells that look blank in a range

parkerbelt

Active Member
Joined
May 23, 2014
Messages
377
I'm trying to find the vba code to "clear contents" - the equivalent of pressing the delete button, for all of the cells that look like they are blank in the range ("H6:0" & lastrow).

I have a cell that has something in it, but it doesn't look like it.
If I delete the contents of the cell, my macro works correctly.
 
Again are you sure it is one of the problem cells?
That is, if you select that cell and hit Backspace, does your other formula come good?
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Again are you sure it is one of the problem cells?
That is, if you select that cell and hit Backspace, does your other formula come good?


If I hit backspace on the problem cell my formula works, however Code(cell) still produces a #value. Its got me stumped
 
Last edited:
Upvote 0
If I hit backspace on the problem cell my formula works,
Thanks for the confirmation. Possibly you have cells that contain a formula returning "" or the cells previously had a formula returning "" and has subsequently been copied and paste special - values or the export produces a similar result.

What happens if you select one of the columns of data including at least one of these problem cells and then do ...
Data -> Text to Columns -> Finish
.. and repeat for the other 3 columns?

By the way, what is your other formula that is being messed up by these cells?
 
Upvote 0
Thank your for helping with this Peter.

I think it must be something with the extract.

For further context I am dealing with time extracted time data looking for exceptions. The formula reads = ((B-C-D)-A)*24 .... with the expected result being 0. The * 24 is to get it to decimals. Unfortunaly i cannot do any calculations without filtering to blank and clearing the blank cells from column B, C, and D. I was hoping there was a macro i can run over all columns to essential clear the data.


ABCDExpected Result
35:0035:00
0​
0:00
0​
4:454:15
-0.5​
38:0039:421:42
0​
38:0038:00
0​
38:0042:154:15
0​
35:00
-35​
35:0035:00
0​
38:0042:154:15
0​
38:0039:421:42
0​
24:0032:008:00
0​
 
Upvote 0
What was the result of this?
What happens if you select one of the columns of data including at least one of these problem cells and then do ...
Data -> Text to Columns -> Finish
.. and repeat for the other 3 columns?
 
Upvote 0
What was the result of this?

Hi Peter,

I hope you had a good weekend.

If i use text to column it fixes the problem cells that then allows the formula to work. Does this result give an indication on what could be hidden in the cells to have them not being originally read as blank? I am hoping to automate as much as possible.

Thanks.
 
Upvote 0
I am hoping to automate as much as possible.
Assuming that the 4 columns of values are A:D, with the actual data starting in row 2, try this macro with a copy of your workbook.

VBA Code:
Sub TTC()
  Dim i As Long
  
  For i = 1 To 4
    Range(Cells(2, i), Cells(Rows.Count, i).End(xlUp)).TextToColumns DataType:=xlDelimited, Tab:=False, Semicolon:=False, Comma:=False, Space:=False, Other:=False
  Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,840
Members
449,471
Latest member
lachbee

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