I'm new to VBA and trying to learn a few tricks from this forum. I have some code below that I cannot get to work correctly.
I want to show or hide 3 different charts based on the cell value in G20. I have a data validation list in G20 that has 3 options, Estimate, Goal, or Actual cost. I want the user to be able to choose a name from the list and a different chart to appear.
I think I'm close but I'm probably missing something...Right now it will only show Chart 2.
Thanks for any help!
I want to show or hide 3 different charts based on the cell value in G20. I have a data validation list in G20 that has 3 options, Estimate, Goal, or Actual cost. I want the user to be able to choose a name from the list and a different chart to appear.
I think I'm close but I'm probably missing something...Right now it will only show Chart 2.
Thanks for any help!
Code:
Sub getchart()
If Range("G20") = "Estimate" Then
Sheets("Overview").ChartObjects("BudgetOverview").Visible = True
Sheets("Overview").ChartObjects("Chart 1").Visible = False
Sheets("Overview").ChartObjects("Chart 2").Visible = False
If Range("G20") = "Goal" Then
Sheets("Overview").ChartObjects("BudgetOverview").Visible = False
Sheets("Overview").ChartObjects("Chart 1").Visible = True
Sheets("Overview").ChartObjects("Chart 2").Visible = False
Else
Sheets("Overview").ChartObjects("BudgetOverview").Visible = False
Sheets("Overview").ChartObjects("Chart 1").Visible = False
Sheets("Overview").ChartObjects("Chart 2").Visible = True
End If
End If
End Sub