LPittenger
New Member
- Joined
- Aug 16, 2008
- Messages
- 10
I am trying, when a certain cell changes, to delete the contents of a number of other cells.
Because the particular cells will vary, I am referring to them indirectly - named cells contain the Excel references to both the "trigger" cell and the "to erase" cells.
Thus the start of my VB macro is:
------------------
Private Sub Worksheet_Change(ByVal Target As Range)
Dim clrRef As String
clrRef = Range("TriggerCell").Cells.Text
If Not Intersect(Target, Range(clrRef)) Is Nothing Then
:
:
------------------
This works. If picks up the reference to the triggering cell as a text string in the cell named "TriggerCell" and then finds thta cell itself through Range(clrRef).
I use the same trick to figure out what cells need to be cleared
------------------
:
:
Dim clrCells As String
clrCells = Range("ClearArea").Cells.Text
For Each c In Range(clrCells)
<?????????>
????????
Next
End If
---------------------
This also works, to pick up the proper range of cells whose refernce is recorded as a text string in the cell named "ClearArea". I've stepped through the debugger and seen that 'c' in the For loop properly takes each cell value in turn from the list provided in the "ClearArea"-named cell.
Here's the problem -- I CAN'T GET THE CELL VALUES TO CLEAR!
I've tried everything I can think of in place of ????????<?????????>
c.Value = ""
c.Value2 = ""
c.Cells.Value = ""
c.Cells(1,1).Value = ""
c.ClearContents
Range(c.Address).Value = ""
I tried no for loop, and just did:
Range(clrCells).ClearContents
Nothing works. Every cell, each correctly found in turn by 'c', remains unaffected.
What should I be doing?!
thanks!
Because the particular cells will vary, I am referring to them indirectly - named cells contain the Excel references to both the "trigger" cell and the "to erase" cells.
Thus the start of my VB macro is:
------------------
Private Sub Worksheet_Change(ByVal Target As Range)
Dim clrRef As String
clrRef = Range("TriggerCell").Cells.Text
If Not Intersect(Target, Range(clrRef)) Is Nothing Then
:
:
------------------
This works. If picks up the reference to the triggering cell as a text string in the cell named "TriggerCell" and then finds thta cell itself through Range(clrRef).
I use the same trick to figure out what cells need to be cleared
------------------
:
:
Dim clrCells As String
clrCells = Range("ClearArea").Cells.Text
For Each c In Range(clrCells)
<?????????>
????????
Next
End If
---------------------
This also works, to pick up the proper range of cells whose refernce is recorded as a text string in the cell named "ClearArea". I've stepped through the debugger and seen that 'c' in the For loop properly takes each cell value in turn from the list provided in the "ClearArea"-named cell.
Here's the problem -- I CAN'T GET THE CELL VALUES TO CLEAR!
I've tried everything I can think of in place of ????????<?????????>
c.Value = ""
c.Value2 = ""
c.Cells.Value = ""
c.Cells(1,1).Value = ""
c.ClearContents
Range(c.Address).Value = ""
I tried no for loop, and just did:
Range(clrCells).ClearContents
Nothing works. Every cell, each correctly found in turn by 'c', remains unaffected.
What should I be doing?!
thanks!