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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
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,200
Messages
6,123,612
Members
449,109
Latest member
Sebas8956

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