ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Clearing Values in a Range under certain conditions (https://www.excelbanter.com/excel-programming/377008-clearing-values-range-under-certain-conditions.html)

Barb Reinhardt

Clearing Values in a Range under certain conditions
 
I'd like to clear values from myRange under either of the following conditions

If the cell doesn't contain a formula OR if the cell is locked.

I have the following CODE

For Each r In myRange
Debug.Print r.Row, r.Formula, r.locked

If r.Formula = No Then
r.ClearContents
End If
Next r

I see that r.formula returns No when there is a formula and r.locked returns
True or False.

Barb Reinhardt

Clearing Values in a Range under certain conditions
 
I figured it out. I forgot to remove a more global clearcontents line.

"Barb Reinhardt" wrote:

I'd like to clear values from myRange under either of the following conditions

If the cell doesn't contain a formula OR if the cell is locked.

I have the following CODE

For Each r In myRange
Debug.Print r.Row, r.Formula, r.locked

If r.Formula = No Then
r.ClearContents
End If
Next r

I see that r.formula returns No when there is a formula and r.locked returns
True or False.


Bob Phillips

Clearing Values in a Range under certain conditions
 
For Each r In myRange
If Not r.HasFormula Or r.Locked Then
r.ClearContents
End If
Next r


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Barb Reinhardt" wrote in message
...
I'd like to clear values from myRange under either of the following

conditions

If the cell doesn't contain a formula OR if the cell is locked.

I have the following CODE

For Each r In myRange
Debug.Print r.Row, r.Formula, r.locked

If r.Formula = No Then
r.ClearContents
End If
Next r

I see that r.formula returns No when there is a formula and r.locked

returns
True or False.





All times are GMT +1. The time now is 07:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com