View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Combine Intersect Range in If statements

I don't understand what you're doing, but maybe this will give you an outline:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count 1 Then Exit Sub

On Error GoTo ErrHandler

If Not Intersect(Me.Range("L2:m20"), Target) Is Nothing Then
'you're in L2:M2, so do the stuff for L2:M2 here
'some code
'some more code
Application.EnableEvents = False
'change some cells on the worksheet

ElseIf Not Intersect(Me.Range("A2:B2"), Target) Is Nothing Then
'you're in A2:B2
'do what you need
Application.EnableEvents = False
'change some different cells on the worksheet

End If

ErrHandler:
Application.EnableEvents = True
End Sub


Ben Dummar wrote:

I am trying to combine the two intersect ranges below into one macro that is
in a worksheet tab. The outside if range works but the inside one doesn't.
What do I need to do to fix it?

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

Dim R As Long
R = Target.Row

On Error GoTo ErrHandler
Application.EnableEvents = True


If Not Intersect(Range("L2:m20"), Target) Is Nothing Then
If Not Intersect(Range("A2:B2"), Target) Is Nothing Then
End If

If Target.Column < 9 Then Exit Sub
If Target.Row = 1 Then Exit Sub

Target.Offset(0, -2).Value = Date '<<== CHECK RANGE
End If

If Target.Column < 2 Then Exit Sub
If Target.Row = 1 Then Exit Sub

Target.Offset(0, 2).Value = Date




ErrHandler:
Application.EnableEvents = True
End Sub

Thanks,

Ben


--

Dave Peterson