PDA

View Full Version : Solved: Referencing a Name Range with VBA



JimS
02-16-2009, 09:19 AM
I have a day off and apparently so does my brain.

I want to ClearContents if a Zero is in the Cell of a Name Range.

This code does not work.

What am I missing?

OTZeros is the Range Name


Sub DelZeros()
Dim zRng As String

zRng = Range("OTZeros")
For Each Cell In zRng
If Cell.Value = "0" Then Cell.ClearContents
Next Cell

End Sub


Thanks...

Jim

MaximS
02-16-2009, 09:31 AM
try this:


Sub DelZeros()
Dim zRng As Range
Set zRng = Range("OTZeros") 'I presume OTZeros is Named Range

For Each Cell In zRng
If Cell.Value = "0" Then Cell.ClearContents
Next Cell

End Sub

mdmackillop
02-16-2009, 09:58 AM
It you're not using the Variable range name elsewhere, then

For Each Cell In Range("OTZeros")

JimS
02-16-2009, 10:14 AM
Thank you very much...

Jim