Question

I am trying to call a macro named "RE_environmental" when the cell named "RE_1" is changed (i.e. they mark a X in the cell). I've tried several different variations of codes including these two and nothing is happening:

[The first code does work if I use the exact cell location and not the named cell. --> $E$62]

     Private Sub Worksheet_Change(ByVal Target As Range)

     If Target.Address = "RE_1" Then

     Call RE_environmental

     End If

     End Sub

AND

     Private Sub Worksheet_Change(ByVal Target As Range)

     If Range("Name").Select = "RE_1" Then

     Call RE_environmental

     End If

     End Sub

--Thanks in Advanced and please let me know if you need more information.

Was it helpful?

Solution

Use your first answer but make this small change:

Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Address = Range("RE_1").Address Then

        Call RE_environmental

    End If

End Sub

Simple syntax mistake!

Edit: To stop RE_environmental from running once the cell is empty, put the code from RE_environmental inside a do-while (not isempty(Range("RE_1"))) as long as RE_environmental is emptying "RE_1". The user won't be able to edit cells while RE_environmental is running.

OTHER TIPS

If Target is always single-cell range, you can use this one:

If Target.Address = Range("RE_1").Address Then
    Call RE_environmental
End If

If Target can be multicell range use this one:

If Not Intersect(Target, Range("RE_1")) Is Nothing Then
    Call RE_environmental
End If
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top