if Cell B1 = "Day1" show chart

  • Thread starter Thread starter rachitm
  • Start date Start date
R

rachitm

Is there is a function that I could use , where if a cell is equal to
Day1, it would show me an already created chart and if B1 is not "Day1"
it would hide that chart?

Any help is appreciated!
 
Paste this in the code for the worksheet if your chart is a worksheet.
If it's an object, you can replace the sheet visible statement with the

ActiveSheet.ChartObjects("Chartname").Visible = False

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$1" Then
If Target.Value = "Day1" Then
Sheets("Chart1").Visible = True ' <== change this if its
an object
Else
Sheets("Chart1").Visible = False ' <== change this if its
an object
End If
End If

End Sub

Rob
 
Right click the sheet tab and choose View Code. In the code module that
opens up, paste the following code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("B1").Address Then
Me.ChartObjects(1).Visible = (StrComp("Day1", _
Target.Text, vbTextCompare) = 0)
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)
 
Thank You! This worked perfect!
Thanks a lot...

Chip said:
Right click the sheet tab and choose View Code. In the code module that
opens up, paste the following code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("B1").Address Then
Me.ChartObjects(1).Visible = (StrComp("Day1", _
Target.Text, vbTextCompare) = 0)
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top