Autorun macro when cell value change

sureshtrb

Board Regular
Joined
Mar 24, 2013
Messages
106
I am not an excel expert and need guidance.
I have made some graphs in one sheet and when I update the cell value in other sheet the graph is changing automatically. but i want to show the value for each day in the graph bar chart. I don't want to show the "0" value for future days. I was unable to run the macro automatically and only when i press run macro it is executing.

Below code taken from web and when I use this it asks for select the chart first. If is select it is running.
The code to run in my sheet chart 7 automatically when I update the cell values

Code:
Sub Show_Labels_Greater_Than_Zero()

    Dim srs As Series, i As Long, cht As Chart
    
    On Error Resume Next
        Set cht = ActiveChart
    On Error GoTo 0
    
    If cht Is Nothing Then
       MsgBox "Please select a chart first.", vbInformation, "No Chart Selected"
        
   Else
        For Each srs In cht.SeriesCollection
            For i = 1 To UBound(srs.Values)
                srs.Points(i).HasDataLabel = srs.Values(i) > 0
            Next i
        Next srs
    End If
        
End Sub
Thanks in advance.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Just call this sub routine on the sheets SelectionChange Event. You will find this event by pressing Alt+11 then Press Ctrl+R Shoose the Sheet on which the your Chart is drawn Now select worksheet Right hand side Combo box at top and select SelectionChange option from next one.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
     Call [FONT=monospace]Show_Labels_Greater_Than_Zero[/FONT]
End Sub
Regards
Prince
 
Upvote 0
Thanks for your reply and done as you recommended but still the macro is asking for selecting the graph and also not running automatically. My requirement is i dont want the user to run the macro and whenever he updates the other sheet and if the value changes in the graph sheet, the macro should run automatically.
Hope its clear and do need further details, let me know pl.
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top