set cell contents to Zero but keep cell formula in VBA

R

Ruth_C

I have a spreadsheet with 3000 and some rows. I am using the code below to
initialise cells to 0 and this works fine. The problem is that some of the
cells contain formulae and when I initialise to 0, the formulae are not kept.
I just want to initialize cell contents and not loose the cell formulae.
Any suggestions in VBA please?

Sub initializeCells()
v = 0#
n = Cells(Rows.count, "C").End(xlUp).Row
Range("C13:F" & n).Value = v
End Sub
 
J

Joel

Sub initializeCells()

LastRow = Cells(Rows.Count, "C").End(xlUp).Row
Set DataRange = Range("C13:F" & LastRow)
DataRange.SpecialCells(xlCellTypeConstants) = 0

End Sub
 
R

Ruth_C

Thank you Joel works like a charm
--
Ruth_C


Joel said:
Sub initializeCells()

LastRow = Cells(Rows.Count, "C").End(xlUp).Row
Set DataRange = Range("C13:F" & LastRow)
DataRange.SpecialCells(xlCellTypeConstants) = 0

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top