-
Solved: Referencing a Name Range with VBA
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
-
try this:
[VBA]
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
[/VBA]
-
It you're not using the Variable range name elsewhere, then
[VBA]
For Each Cell In Range("OTZeros")
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
Thank you very much...
Jim
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules