View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default refer to cell relative to range

just create the combined range with Union()

set united=Union(Range("Skill1"),Range("Skill2"))
If Not (Application.Intersect(Target, united) Is Nothing) Then
--
Gary''s Student - gsnu200751


"Horatio J. Bilge, Jr." wrote:

I have a worksheet shere I periodically update the data in a range. The
column to the right of the range displays the date when I last updated that
row of data (see code below). I would like to change the code so it will do
the same thing with whatever named range I include.

This is what I have:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim WS As Worksheet
Set WS = Worksheets("Sheet1")
If Not (Application.Intersect(Target, Range("Skill1")) Is Nothing) Then
With WS.Cells(Target.Row, 13)
.Value = Now
.NumberFormat = "mm/dd/yyyy"
End With
Exit Sub
End If
End Sub

This is what I tried. I thought this way I could easily add additional
ranges as ElseIf statements. I get an error, "Argument is not optional."
Private Sub Worksheet_Change(ByVal Target As Range)
Dim WS As Worksheet
Set WS = Worksheets("Sheet1")
If Not (Application.Intersect(Target, Range("Skill1")) Is Nothing) Then
GoTo Revise_Date
ElseIf Not (Application.Intersect(Target, Range("Skill2")) Is Nothing) Then
GoTo Revise_Date
Else: Exit Sub
End If

Revise_Date:
With WS.Cells(Target.Row, Target.Range.Offset(0,1))
.Value = Now
.NumberFormat = "mm/dd/yyyy"
End With
Exit Sub
End Sub