Macro does not clear the contents!
I have a worksheet which has an income and expense analysis for 12 months. I would like to re-use it by keeping the formula and format intact, but clear the contents of each cell. So, if a cell does not have a formula, but has a text or number, it should be clear after I run the macro.
I came up with a simple macro, but did not seem to work, so I have posted the question on the code forum site. I have now two macros in which one of the macro does not seem to have a syntax error, but does not do the job, i.e. it loops through each sheet, but does not clear the contents. The other macro has a syntax error.
Could someone please spot what is wrong with these two codes?
Cheers
Sub clearcontents()
Dim Rng As Range, oCell As Range
Set Rng = Range("A2:A100")
For sh = 1 To Worksheets.Count '+for each sheet
Sheets(sh).Activate '+
For Each oCell In Rng
If oCell.HasFormula Then
Exit Sub
Else
oCell.clearcontents
End If
Next
Next sh '+
End Sub
Sub snb()
For Each sh In Sheets
sh.Range("A2:A100").SpecialCells(2).clearcontents ‘ a line which shows an error
Next sh
End Sub
- BUILDING A WEBSITE 541 20
- Claiming Homes Expenses 124 2
- CGT - PPR working abroad 76 1
- Payroll software 203 5
- Rent free property 265 7




Try this