Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Excel VBA clear contents of cells within set ranges

I’m having a issue getting the syntax right on the below few lines of code.
essentially i want Excel to remove the contents of certain ranges per row but I need to avoid cells in between those ranges which have important formulas in them. That’s why i cant use the ‘clear entire row contents’ approach

Boiled down I’d like to clear the contents of the ranges "C(e):L(e)","N(e):V(e)")

But i’m going wrong with the syntax I think
any advice on this one?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

   Dim e As Integer
For e = 14 To 213
    If ActiveSheet.Cells(e, 35).Value = "0" Then Range("C" & "e":"L" & "e").ClearContents

>Solution :

You need to remove the quotes around the e or else it just evaluates as the text e rather than the number your referring to in the for-loop.

Dim e As Integer
For e = 14 To 213
    If ActiveSheet.Cells(e, 35).Value = "0" Then Range("C" & e & ":L" & e & ",N" & e & ":V" & e).ClearContents
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading