我有一个电子表格,其中包含数百个键。一些公司在电子表格中有多个债券。目前,我将每个单元格添加到其自己的SeriesCollection中,然后将其添加到散点图中。我希望将SeriesCollections按公司分组,然后进行遍历,而不仅仅是每个都包含一个数据点。为此,我假设我需要遍历“公司名称”列,找到重复项,并将它们添加到一个数组中,然后在添加到SeriesCollection时可以对其进行遍历。
Dim dupArray(256, 25) As Variant
For Each srs In tkrng.SpecialCells(xlCellTypeVisible)
If srs <> "" Then
If IsEmpty(dupArray(Application.Match(srs, tkrng, 0), 1)) = True Then
dupArray(Application.Match(srs, tkrng, 0), 1) = Application.Match(srs, tkrng, 0)
Else
i = 1
While IsEmpty(dupArray(Application.Match(srs, tkrng, 0), 1 + i)) = False
i = i + 1
Wend
dupArray(Application.Match(srs, tkrng, 0), 1 + i) = Application.Match(srs, tkrng, 0)
End If
srs.Offset(0, 4) = Application.Match(srs, tkrng, 0)
End If
Next srs
'Above is not currently used for anything
'###########################################################
'Loop for adding visible cells to graph
m = 1
For Each cl In rng.SpecialCells(xlCellTypeVisible)
If m > 8 Then
m = 1
End If
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(p).Values = cl
'Choosing which visible data to add based on dropdown box
If ActiveSheet.Range("I12").Value = 1 Then
ActiveChart.SeriesCollection(p).XValues = cl.Offset(0, -2)
ElseIf ActiveSheet.Range("I12").Value = 2 Then
ActiveChart.SeriesCollection(p).XValues = cl.Offset(0, -3)
ElseIf ActiveSheet.Range("I12").Value = 3 Then
ActiveChart.SeriesCollection(p).XValues = cl.Offset(0, -4)
ElseIf ActiveSheet.Range("I12").Value = 4 Then
ActiveChart.SeriesCollection(p).XValues = cl.Offset(0, -5)
ElseIf ActiveSheet.Range("I12").Value = 5 Then
ActiveChart.SeriesCollection(p).XValues = cl.Offset(0, -6)
Else
ActiveChart.SeriesCollection(p).XValues = cl.Offset(0, -7)
End If
'Applying name and marker style
ActiveChart.SeriesCollection(p).Name = "Series " & p
ActiveChart.SeriesCollection(p).MarkerStyle = mc(m)
m = m + 1
p = p + 1
k = k + 1
Next cl