VBA Macro to clear contents every two cells down a column - not working

Candidont

New Member
Joined
Mar 21, 2018
Messages
3
Can someone diagnose?

Sub deleteCellContents()
Dim x As Integer
x = 7
Do While x < 74
With Worksheets("Sheet1").Range(Cells(x, 1)).ClearContents
x = x + 2
End With
Loop
End Sub

Thanks
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi & welcome to MrExcel.

Your With statement is wrong & unneeded, try
Code:
Sub deleteCellContents()
   Dim x As Integer
   x = 7
   Do While x < 74
      Worksheets("Sheet1").Range(Cells(x, 1)).ClearContents
      x = x + 2
   Loop
End Sub
 
Upvote 0
Thanks Fluff but there's still something wrong with this line though...

Worksheets("Sheet1").Range(Cells(x, 1)).ClearContents

I get an application-defined or object-defined error message
 
Upvote 0
Oops missed that bit, try
Code:
Worksheets("Sheet1").Range("A"&x).ClearContents
 
Upvote 0
yeah either that above will work or also

Code:
Worksheets("Sheet1").Cells(x, 1).ClearContents
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,589
Messages
6,120,416
Members
448,960
Latest member
AKSMITH

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