Use a mouse hovering technique to create an interactive chart
I recently discovered an interesting technique about using a user defined function in a HYPERLINK function. Jordan at the Option Explicit vba blog blogged about this more than a year ago. He made an amazing Periodic Table of Elements.
I used his technique in this basic chart.
My values are in a table in a different sheet, the user defined function filters column 1. I found out that you can´t clear a table filter from the user defined function:
Worksheets("Sheet1").ListObjects("Table1").Range.AutoFilter Field:=1 won´t work!
I had to use "*" to show all values in table column 1.
Worksheets("Sheet1").ListObjects("Table1").Range.AutoFilter _
Field:=1, Criteria1:="*", Operator:=xlFilterValues
VBA code
Function MouseHover(str As String, bln As Boolean)
If bln = False Then
If str = "Deselect all" And Sheet2.Range("I11") <> str Then
Sheet2.Range("I11") = "Deselect all"
Worksheets("Sheet1").ListObjects("Table1").Range.AutoFilter _
Field:=1, Criteria1:="", Operator:=xlFilterValues
Exit Function
End If
If Sheet2.Range("I11") <> str Then
Sheet2.Range("I11") = str
ActiveSheet.ChartObjects("Chart 4").Chart.SetSourceData Source:=Sheets("Sheet1").Range("Table1[#All]")
ActiveSheet.ChartObjects("Chart 4").Chart.PlotBy = xlRows
Worksheets("Sheet1").ListObjects("Table1").Range.AutoFilter _
Field:=1, Criteria1:=str, Operator:=xlFilterValues
End If
Else
If Sheet2.Range("I11") <> str Then
Sheet2.Range("I11") = CStr(str)
Worksheets("Sheet1").ListObjects("Table1").Range.AutoFilter _
Field:=1, Criteria1:="*", Operator:=xlFilterValues
ActiveSheet.ChartObjects("Chart 4").Chart.SetSourceData Source:=Sheets("Sheet1").Range("Table1[[#All],[Column1]], Table1[[#All],[" & str & "]]")
ActiveSheet.ChartObjects("Chart 4").Chart.PlotBy = xlColumns
End If
End If
End Function
The user defined function saves a value in cell I11. I made it invisible by applying a custom formatting to it: ;;;
Formula in cell I8:
I wanted to remove the hyperlink effect so I added "Apple"& to the formula.
Download excel *.xlsm file
Interactive chart - mouse hover.xlsm
Related posts:
Interactive chart in excel (vba)
Quickly filter a column in an excel table
Copy excel table filter criteria (vba)


















Hey - thanks for the mention!
This site is a great resource, too.
This is really neat!
I have so many ideas but have so much to learn.
This is a great site!
Jordan and Gerald,
Thanks!
By the way, if you want to add labels to your hyperlinks that won't redirect the user when clicked, you can write it as:
IFERROR(HYPERLINK(MouseHover("Apple", FALSE),"Apple"),"Apple")
In lieu of concatenating above
J
Oscar, how do you get the mouse over event to kick in?
duh..........sorry I figured that out, but thanks for this cool tip!
Jordan,
Thanks!
chrisham,
I forgot to mention that! Conditional formatting compares the value in cell I11.
Hi, its really gr8 resource for learner and developer. I am facing one problem whenever i m trying to download .xlsm file getting .zip file and finally after extracting getting .xlm files from which not getting the impact. which is talked about.
Please help, n thanx.
Shiven