waimea
02-27-2019, 05:41 AM
Hi,
I have an userform with a textbox and a combobox and when I select an item in the combobox I would like to show the chart for that item in an image element in the userform.
Also I am trying to search a textbox and display a chart based on all matches, so if there are 3 matches the chart would show values for all those items. If there are 5 matches I would like to see a chart with the combined values of those 5 items.
The userform is called userform1, the combobox is called combobox1, the textbox is called textbox1.
I have code to create a chart, export it to a gif file and then load the gif file in the image1 box.
Public Sub GetChart()
Dim CurrentChart As Variant
Dim Fname As Variant
On Error Resume Next
Set CurrentChart = Sheet1.ChartObjects("Test").Chart
CurrentChart.Parent.Width = 250
CurrentChart.Parent.Height = 250
' Fname = ThisWorkbook.Path & "/temp.gif"
' CurrentChart.Export Filename:=Fname, FilterName:="GIF"
Image1.Picture = LoadPicture(Fname)
' Delete file
'Kill Fname
End Sub
Code to create a chart for one item below:
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim selectedRow As Integer
selectedRow = ListBox1.ListIndex + 1
Sheet1.Select
Cells(selectedRow + 1, 1).EntireRow.Select
ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select
Dim rngChart As Range
With Sheets("Sheet1")
On Error Resume Next
Set rngChart = Intersect(.Range("A:A, D:D, F:F, E:E"), .Rows(selectedRow))
End With
'Name the chart
ActiveChart.Parent.Name = "Test"
ActiveChart.SetSourceData Source:=rngChart
'Delete all sheets on sheet1
'Worksheets("Sheet1").ChartObjects.Delete
End Sub
I don't know how to go from combobox selection to show that peticular chart and I don't know how to display a chart for say 5 matches in the textbox search.
All suggestions on how I can improve my code are welcome!
I have an userform with a textbox and a combobox and when I select an item in the combobox I would like to show the chart for that item in an image element in the userform.
Also I am trying to search a textbox and display a chart based on all matches, so if there are 3 matches the chart would show values for all those items. If there are 5 matches I would like to see a chart with the combined values of those 5 items.
The userform is called userform1, the combobox is called combobox1, the textbox is called textbox1.
I have code to create a chart, export it to a gif file and then load the gif file in the image1 box.
Public Sub GetChart()
Dim CurrentChart As Variant
Dim Fname As Variant
On Error Resume Next
Set CurrentChart = Sheet1.ChartObjects("Test").Chart
CurrentChart.Parent.Width = 250
CurrentChart.Parent.Height = 250
' Fname = ThisWorkbook.Path & "/temp.gif"
' CurrentChart.Export Filename:=Fname, FilterName:="GIF"
Image1.Picture = LoadPicture(Fname)
' Delete file
'Kill Fname
End Sub
Code to create a chart for one item below:
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim selectedRow As Integer
selectedRow = ListBox1.ListIndex + 1
Sheet1.Select
Cells(selectedRow + 1, 1).EntireRow.Select
ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select
Dim rngChart As Range
With Sheets("Sheet1")
On Error Resume Next
Set rngChart = Intersect(.Range("A:A, D:D, F:F, E:E"), .Rows(selectedRow))
End With
'Name the chart
ActiveChart.Parent.Name = "Test"
ActiveChart.SetSourceData Source:=rngChart
'Delete all sheets on sheet1
'Worksheets("Sheet1").ChartObjects.Delete
End Sub
I don't know how to go from combobox selection to show that peticular chart and I don't know how to display a chart for say 5 matches in the textbox search.
All suggestions on how I can improve my code are welcome!