code doesn't work

yad

New Member
Joined
Oct 6, 2021
Messages
14
Office Version
  1. 2019
Platform
  1. Windows
this code modifies the axis of my waterfall chart automatically , it is connected with some slicers . now the waterfall chart is in sheet 5 but when I change the slicer from the sheet 2 (same slicer in two different sheets) the waterfall doesn't change .

here is my code :
Private Sub Worksheet_Change(ByVal Target As Range)


If ActiveSheet.Name = "Sheet3" Then
If ActiveSheet.Name = "Sheet2" Then
If Range("B5").Value <> 0 Then



ChartObjects("Chart 8").Activate

With ActiveChart.Axes(xlValue)

.MinimumScale = 0.9 * Application.WorksheetFunction.Min(Range("b5:b51").Value)
.MaximumScale = 1.1 * Application.WorksheetFunction.Max(Range("b5:b51").Value)


End With


Range("A1").Select
End If
End If
End If

End Sub
 

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.
Am no VBA expert but, hold on,

Code:
If ActiveSheet.Name = "Sheet3" Then
 If ActiveSheet.Name = "Sheet2" Then

How can the SheetName be BOTH "Sheet3" AND "Sheet2" at the same time?
Shouldn't there be an OR there somewhere?
 
Upvote 0
hello ,thank you for highlighting it , it was a mistake while i was trying to modify the code , here the code i want to fix :
Private Sub Worksheet_Change(ByVal Target As Range)


If ActiveSheet.Name = "Sheet2" Then
If Range("B5").Value <> 0 Then



ChartObjects("Chart 8").Activate

With ActiveChart.Axes(xlValue)

.MinimumScale = 0.9 * Application.WorksheetFunction.Min(Range("b5:b51").Value)
.MaximumScale = 1.1 * Application.WorksheetFunction.Max(Range("b5:b51").Value)


End With


Range("A1").Select
End If
End If
End If
 
Upvote 0

Forum statistics

Threads
1,215,982
Messages
6,128,105
Members
449,421
Latest member
AussieHobbo

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