Hiding donut chart using VBA

SYKEMAKAVELI

New Member
Joined
Apr 18, 2023
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have an excel cell with a range name "Progress_box_toggle", with values "TRUE" or "FALSE". It is contained within an excel tab called "Dashboard".

I want to include code in the Wooksheet_change private sub to hide or show a donut graph based on the value of this range.
If the value is "TRUE", then the donut chart named "Donut_progress_main" should be visible, otherwise it should be hidden.

The code that I've used so far within the Worksheet_change private sub is as follows:
If Not Intersect(Target, Range("Progress_box_toggle")) Is Nothing Then ' check if the changed cell is the one with the range name "Progress_box_toggle"

If Range("Progress_box_toggle").Value = "TRUE" Then ' check if the value of the range is "TRUE"

Sheets("Dashboard").ChartObjects("Donut_progress_main").Visible = True ' show the chart
Else

Sheets("Dashboard").ChartObjects("Donut_progress_main").Visible = False ' hide the chart
End If
End If

For some reason it isn't working.
Does anyone have any suggested changes?

Thanks
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Instead of testing for the text value "TRUE", try testing with the logical value TRUE...

VBA Code:
If Range("Progress_box_toggle").Value = TRUE Then

By the way, your code can be re-written as follows...

VBA Code:
If Not Intersect(Target, Range("Progress_box_toggle")) Is Nothing Then ' check if the changed cell is the one with the range name "Progress_box_toggle"

    Sheets("Dashboard").ChartObjects("Donut_progress_main").Visible = Range("Progress_box_toggle").Value

End If

Hope this helps!
 
Upvote 0
Thank you for your help with this and your simplification of my code. Much appreciated.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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