View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Barb Reinhardt Barb Reinhardt is offline
external usenet poster
 
Posts: 3,355
Default Delete Corresponding Cell Using ByVal

Put this in the worksheet change event of the worksheet you are changing.

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myCRange As Excel.Range
Dim myERange As Excel.Range
Dim myRange As Excel.Range

If Target.Count 1 Then Exit Sub

Set myCRange = Me.Range("C4:C22")
Set myERange = myCRange.Offset(0, 2)
Set myRange = Union(myCRange, myERange)


If Not Intersect(Target, myRange) Is Nothing Then
Application.EnableEvents = False

If Not Intersect(Target, myCRange) Is Nothing Then
Target.Offset(0, 2).ClearContents
ElseIf Not Intersect(Target, myERange) Is Nothing Then
Target.Offset(0, -2).ClearContents
End If
Application.EnableEvents = True
End If

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub

--
HTH,

Barb Reinhardt



"David" wrote:

I have two columns of data in C & E. C is for a dollar amount, E is for a
percentage amount. Only ONE of the columns can have data at a time. I'm
trying to set up a ByVal on the sheet so that if data is entered in column C,
the data in the corresponding cell in column E would automatically be deleted
and vice versa. The range right now is C4:C22 and E4:E22, but could be
expanded (I can make that change manually, but it would be nice to have the
ranges be named to so when changes are made, no change to the code is
necessary.
I have the ByVal code with a range, but don't know how to set up the code to
delete the corresponding cell value. I would appreciate help with this.

David