Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default Clearcontents

Vinnie

You can loop through all the dependent cells and clear their contents.
Here's an example that uses the Worksheet_Change event:

Private Sub Worksheet_Change(ByVal Target As Range)

'Stop this sub from running based on changes made here
Application.EnableEvents = False

Dim cell As Range
Dim DepRng As Range

'Changed cell is in A1:I1
If Not Intersect(Target, Me.Range("A1:I1")) Is Nothing Then

'Change cell was deleted
If IsEmpty(Target) Then

'Set up error handling in case their is no dependents
On Error Resume Next

Set DepRng = Target.Dependents

'If there are dependent cells
If Err.Number = 0 Then

'Loop through them and clear them
For Each cell In DepRng.Cells
cell.ClearContents
Next cell
End If
On Error GoTo 0
End If
End If

Application.EnableEvents = True

End Sub

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"Vinnie" wrote in message
...
How do I clear the contents from a range of cells, which are dependent on

another cell being populated. For example, If I enter a Value in cell A1,
A5:A10 are populated with data according to the value entered in A1. A value
in B1 populates data in B5:B10, C1 populates data in C5:C10 etc.....

My question is if I clear either A1,B1 or C1, I also want to clear the

corresponding data in A5:A10, B5:B10, C5:C10 etc

If I only clear A1 & C1 then contents from A range & C range should only

clear. Any ideas would be appreciated.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sheets("Sheet1").Cells.ClearContents Seeker Excel Discussion (Misc queries) 2 October 1st 09 12:00 PM
"ClearContents" command halts code Dave O Excel Discussion (Misc queries) 3 January 10th 08 03:39 PM
Conditional formatting, pastevalues, clearcontents Allllen Excel Discussion (Misc queries) 2 August 30th 06 05:09 PM
ClearContents method on a passed range bryan New Users to Excel 2 January 19th 05 08:49 AM
Error of ClearContents Richard[_23_] Excel Programming 1 January 1st 04 12:23 PM


All times are GMT +1. The time now is 04:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"