Setting ChartData according to the index number in a combobox

RawlinsCross

Active Member
Joined
Sep 9, 2016
Messages
437
This should be fairly straight forward but I'm missing something:

I have a combobox with 13 items that reference a different column of data. I'm trying to tell excel to graph based on the index value of that combobox. It's working but only with the first selection (i.e. index = 0). here's the portion of the code in question.

Code:
If ChartIndex1 = 0 Then
Set ChartData1 = Worksheets("212-R365").Range("F" & r.Row & ":F" & rn1)
ElseIf ChartIndex1 = 1 Then
Set ChartData1 = Worksheets("212-R365").Range("H" & r.Row & ":H" & rn1)
ElseIf ChartIndex1 = 2 Then
Set ChartData1 = Worksheets("212-R365").Range("AK" & r.Row & ":AK" & rn1)
ElseIf ChartIndex1 = 3 Then
Set ChartData1 = Worksheets("212-R365").Range("EA" & r.Row & ":EA" & rn1)
ElseIf ChartIndex1 = 4 Then
Set ChartData1 = Worksheets("212-R365").Range("U" & r.Row & ":U" & rn1)
ElseIf ChartIndex1 = 5 Then
Set ChartData1 = Worksheets("212-R365").Range("AL" & r.Row & ":AL" & rn1)
ElseIf ChartIndex1 = 6 Then
Set ChartData1 = Worksheets("212-R365").Range("P" & r.Row & ":P" & rn1)
ElseIf ChartIndex1 = 7 Then
Set ChartData1 = Worksheets("212-R365").Range("AM" & r.Row & ":AM" & rn1)
ElseIf ChartIndex1 = 8 Then
Set ChartData1 = Worksheets("212-R365").Range("Q" & r.Row & ":Q" & rn1)
ElseIf ChartIndex1 = 9 Then
Set ChartData1 = Worksheets("212-R365").Range("R" & r.Row & ":R" & rn1)
ElseIf ChartIndex1 = 10 Then
Set ChartData1 = Worksheets("212-R365").Range("D" & r.Row & ":D" & rn1)
ElseIf ChartIndex1 = 11 Then
Set ChartData1 = Worksheets("212-R365").Range("T" & r.Row & ":T" & rn1)
ElseIf ChartIndex1 = 12 Then
Set ChartData1 = Worksheets("212-R365").Range("S" & r.Row & ":S" & rn1)
End If
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Something like this:


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim chartdata1 As Range, rn1%, ci%, r As Range, ws As Worksheet, ra
ra = Array("f", "h", "ak", "ea", "u", "al", "p", "am", "q", "r", "d", "t", "s")
Set ws = Sheets("212-R365")
Set r = [3:3]
rn1 = 5
ci = Me.ComboBox1.ListIndex + 1
Set chartdata1 = ws.Range(ra(ci) & r.Row & ":" & ra(ci) & rn1)
MsgBox chartdata1.Address
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,217
Members
453,024
Latest member
Wingit77

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top