I have very simple chart macro code as:
sub chart()
Range("A1:B4").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Sheets("Sheet2").Range("A1:B4")
ActiveChart.ChartType = xlLine
End Sub
I want to control "Sheet" reference using combobox. Combobox has values Sheet1, Sheet2 and Sheet3. I tried using this but it is not working:
sub chart()
Dim sht As String
sht = ComboBox1
'
Range("A1:B4").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Sheets("sht").Range("A1:B4")
ActiveChart.ChartType = xlLine
End Sub
I also tried using & sign on either side of the 'sht' but it is not working. Any ideas?
sub chart()
Range("A1:B4").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Sheets("Sheet2").Range("A1:B4")
ActiveChart.ChartType = xlLine
End Sub
I want to control "Sheet" reference using combobox. Combobox has values Sheet1, Sheet2 and Sheet3. I tried using this but it is not working:
sub chart()
Dim sht As String
sht = ComboBox1
'
Range("A1:B4").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Sheets("sht").Range("A1:B4")
ActiveChart.ChartType = xlLine
End Sub
I also tried using & sign on either side of the 'sht' but it is not working. Any ideas?