Error 13: for cell.ClearContents

Excel_VBA_YT

New Member
Joined
Aug 31, 2021
Messages
3
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi folks,

I am getting Error 13 while running the below code. If the contents of cell is New years day, I want to clear the cells contents.

The bold portion of the code is where the problem seems to be. any suggestions / advise would be great.
---------------------------------------------------------------
Sub Clear_contents()

Dim cell As Range
Dim myrange As Range
Set myrange = Worksheets("Step 1-3 Working Sheet").Range("M13:BA23")
myrange.UnMerge

For Each cell In myrange
If cell.Value = "New Years Day" Then
cell.ClearContents
End If

Next cell

End Sub
------------------------------------------------------------------
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Works fine for me.
IS NYD aan actual text or a formula result
 
Upvote 0
sorry, does not work that results in
"compile error: Each control variable must be variant or Object"
 
Upvote 0
Hard to say but ensure there are no cells in error (like #REF! or #DIV/0!) in the M13:BA23 range.
 
Upvote 0
@Trebor76
Hence my question about formula results.
Hope your keeping safe up there Robert....Are you affected ??
 
Upvote 0
Hi Michael,
As good as can be expected thanks mate. I'm not in a lock down area so that's something.
What about you?
 
Upvote 0
Nah...we're all good down on the Murray river!
 
Upvote 0
Hi,

this worked for me:

VBA Code:
Sub Clear_contents()

Dim cell As Range
Dim myrange As Range
Set myrange = Sheet1.Range("A1:A23")
myrange.UnMerge

For Each cell In myrange
If cell.Value = "New Years Day" Then
cell.ClearContents
End If

Next cell

End Sub

I only changed my range
 
Upvote 0
I am getting Error 13 while running the below code
A type mismatch error on that line would suggest that the cell contains an error value. What do you want to do in that case? Clear it or ignore it?
 
Upvote 0

Forum statistics

Threads
1,215,093
Messages
6,123,067
Members
449,090
Latest member
fragment

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