Only want this macro to run when column A cells 4-13 are selected

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,139
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi everyone,
I have this macro that run anytime the sheet has a change done to it,
however I'd prefer if it only ran anytime Column A cells 4 to 13 were selected
(that's any one of the cells, not all the cells together.)

please can someone show me how to amend it, or what I need to do?

this is the macro:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.Axes(xlValue).Select
    ActiveChart.Axes(xlValue).MinimumScale = Range("e25")
    ActiveChart.Axes(xlValue).MaximumScale = Range("d25")
   
End Sub



thanks

Tony
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Snakehips

Well-known Member
Joined
May 17, 2009
Messages
5,701
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Tony,

Try...
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Range("A4:A13")) Is Nothing Then Exit Sub


   ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.Axes(xlValue).Select
    ActiveChart.Axes(xlValue).MinimumScale = Range("e25")
    ActiveChart.Axes(xlValue).MaximumScale = Range("d25")
   
End Sub

Hope that helps.
 
Upvote 0

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,139
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Snakehips,
Wow, that works perfectly,
big thank you
and on a Saturday!

Tony
 
Upvote 0

Snakehips

Well-known Member
Joined
May 17, 2009
Messages
5,701
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Don't forget that I charge double on a Saturday!
And then of course, there will be the +25% 'works perfectly' supplement.
Please advise postal address for invoice.
 
Upvote 0

Forum statistics

Threads
1,191,707
Messages
5,988,230
Members
440,139
Latest member
ngaicuong2017

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
Top