Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

values from listbox, display chart in form 1

Status
Not open for further replies.

Groubas

MIS
Jul 24, 2006
17
SE
Im quite new at VBA but I have to solve this.
I guess this is a two part question...

1 I want to create a scatter chart but my source data are in a listbox (-devided in two columns). What code should i write to set the listbox columns as source for the chart?

2 Is it possible to display the chart in the form for example in a frame or a new listbox?

This is my code that obviously doesnt work

ActiveChart.SetSourceData Source = frmTrycklinje.lstCoords
ActiveChart.SeriesCollection(1).XValues = lstCoords.Column(0, ListCount)
ActiveChart.SeriesCollection(1).Values = lstCoords.Column(1, ListCount)
 
You'd probably be better off creating a hidden worksheet and populating the values there and using those values to populate your chart.

HTH

Regards,
Zack Barresse

Simplicity is the ultimate sophistication. What is a MS MVP? PODA
- Leonardo da Vinci
 
Thanks Zack

Something similar has crossed my mind... But how do I copy the values from the listbox to the hidden worksheet?
 
Here is some userform code that will populate a sheet with it's values...

Code:
Private Sub cmbPopulate_Click()
    Dim ws As Worksheet, iEnd As Long, i As Long
    Set ws = ThisWorkbook.Sheets("Sheet1")
    iEnd = Me.ListBox1.ListCount
    For i = 1 To Me.ListBox1.ListCount
        ws.Cells(i, "A").Value = Me.ListBox1.List(i - 1)
    Next i
End Sub

Private Sub cmbCloseForm_Click()
    Unload Me
End Sub

Private Sub UserForm_Initialize()
    Dim i As Long
    For i = 1 To 10
        Me.ListBox1.AddItem i
    Next i
End Sub

HTH

Regards,
Zack Barresse

Simplicity is the ultimate sophistication. What is a MS MVP? PODA
- Leonardo da Vinci
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top