"Looping" Code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In a nutshell, I have a list of projects to which I linked a graph that plots data dynamically, based on the active row of the list. I scroll up or down to a particular project title, press the button the macro is assigned to, and the graph is updated with the parameters that correspond to the project title in the active cell.

I'd like to nix the button so that the graph updates automatically when I move the active cell up and down the list. I don't know if this would be "event" driven (ie. prompted by the movement of the active cell), or better accomplished by looping the script.

Here's the code

Sub UpdateChart(
If ActiveCell.Row > 2 And ActiveCell.Row < 20 Then
ActiveSheet.Calculat
End Su

I appreciate your help

E
 
Hi
you may try using the Selection_change worksheet event. Put the
following in your worksheet module (checks for a selection in A2:A20):

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range("A2:A20")) Is Nothing Then Exit Sub
On Error GoTo CleanUp:
With Target
Application.EnableEvents = False
'insert your code to change the chart
End If
End With
CleanUp:
Application.EnableEvents = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top