使用Excel列表框中的选定值制定图例

info_seekeR

我试图将选定的值从list boxinExcel传递到图表中的图例。具体来说,我具有以下格式的某些公司的数据

在此处输入图片说明

我还有一个列表框globalList,其中包含可以选择的公司名称。然后,选定的公司数据将使用VBA传递到图表上。

在此处输入图片说明

但是,我遇到的问题在以下几节中:

初始化变量以保存在globalList中选择的值

listMax = globalList.ListCount - 1
`this creates the upper bound for the list box

For i = 0 To (globalList.ListCount - 1)
    If globalList.Selected(i) = True Then
        companiesSelected = companiesSelected + 1
    End If
    If i = listMax Then
    Exit For
    End If
Next i
`the above is used to retrieve the number of companies that have been selected by a user - whether =0 or > 0

Dim myLegend() As String
ReDim myLegend(0 To (globalList.ListCount - 1))
For i = 0 To (globalList.ListCount - 1)
    If globalList.Selected(i) = True Then
        myLegend(i) = globalList.List(i)
    End If
    If i = listMax Then
    Exit For
    End If
Next i
`this is the array object in which I intend to store company names selected in the list box.

问题是,即使上面创建了myLegend字符串数组,它也包含了用户可能未在列表框中选择的公司的空数组项。即使我能够从数组中删除这些空项目,也会出现以下问题

将保留值从变量传递到图表

    For i = 1 To companiesSelected
    myChart.SeriesCollection(i).Name = myLegend(i)
    Next i

这里的问题是myLegend数组从0开始,而数组SeriesCollection似乎从1开始。因此,我无法将所选项目的字符串值传递给图表的图例。

有人可以指出如何避免这些问题吗?提前谢谢了!

感觉

这是将所选项目提取到一个基于字符串的String数组中的代码(无空项目):

Dim i           As Integer
Dim iCount      As Integer
Dim myLegend()  As String

iCount = 0
With globalList

    ReDim myLegend(1 To .ListCount)
    For i = 0 To .ListCount - 1
        If .Selected(i) = True Then
            iCount = iCount + 1
            myLegend(iCount) = .List(i)
        End If
    Next i

End With

If iCount > 0 Then
    ReDim Preserve myLegend(1 To iCount)
Else
    ReDim myLegend(1 To 1)
    myLegend(1) = "Nothing here!"
End If

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用Excel列表框中的选定值制定图例

来自分类Dev

无法访问列表框中的选定值

来自分类Dev

Visual Basic:如何使用循环从列表框(Selectionmode Multisimple)中获取所有选定的值?

来自分类Dev

VBA EXCEL:使用列表框中的值作为Match WorksheetFunction中的Lookup值

来自分类Dev

获取列表框的选定索引和选定值

来自分类Dev

如何从元组列表中为PySimpleGUI列表框中的选定值返回第二项

来自分类Dev

在Excel中使用操作按钮从列表框分配值

来自分类Dev

在tkinter python中使用excel的值时,列表框中没有重复项?

来自分类Dev

根据列表框中的选定项目显示类的属性值

来自分类Dev

如何从列表框C#Windows应用程序中获取多个选定值

来自分类Dev

如何在多列列表框中获取选定的值

来自分类Dev

从angularjs的列表框中获取确切的选定值

来自分类Dev

为什么WPF列表框中的选定值为null?

来自分类Dev

如何在单击时从 html 选定列表框中删除值

来自分类Dev

如何将多个列表框中的选定值添加到特定范围?

来自分类Dev

从使用AJAX更新的列表框中获取最新值

来自分类Dev

使用数组中的值填充下拉列表框

来自分类Dev

如何显示从字典到列表框的选定值

来自分类Dev

Excel VBA:根据文本框中设置的值在列表框中搜索值

来自分类Dev

Excel VBA:根据文本框中设置的值在列表框中搜索值

来自分类Dev

使用C#从列表框中的选定项目中获取ValueMember

来自分类Dev

在WhereGlause for ArcGis中使用列表框中的多个选定项

来自分类Dev

使用jQuery从asp列表框中获取选定项目的计数

来自分类Dev

从列表框(ObservableCollection)中删除选定的项目

来自分类Dev

从列表框(ObservableCollection)中删除选定的项目

来自分类Dev

列表框中的多个默认选定项

来自分类Dev

从列表框中的选定项目中删除3行

来自分类Dev

从选中的列表框中检索选定的项目?

来自分类Dev

从Access中的列表框中提取选定的行

Related 相关文章

  1. 1

    使用Excel列表框中的选定值制定图例

  2. 2

    无法访问列表框中的选定值

  3. 3

    Visual Basic:如何使用循环从列表框(Selectionmode Multisimple)中获取所有选定的值?

  4. 4

    VBA EXCEL:使用列表框中的值作为Match WorksheetFunction中的Lookup值

  5. 5

    获取列表框的选定索引和选定值

  6. 6

    如何从元组列表中为PySimpleGUI列表框中的选定值返回第二项

  7. 7

    在Excel中使用操作按钮从列表框分配值

  8. 8

    在tkinter python中使用excel的值时,列表框中没有重复项?

  9. 9

    根据列表框中的选定项目显示类的属性值

  10. 10

    如何从列表框C#Windows应用程序中获取多个选定值

  11. 11

    如何在多列列表框中获取选定的值

  12. 12

    从angularjs的列表框中获取确切的选定值

  13. 13

    为什么WPF列表框中的选定值为null?

  14. 14

    如何在单击时从 html 选定列表框中删除值

  15. 15

    如何将多个列表框中的选定值添加到特定范围?

  16. 16

    从使用AJAX更新的列表框中获取最新值

  17. 17

    使用数组中的值填充下拉列表框

  18. 18

    如何显示从字典到列表框的选定值

  19. 19

    Excel VBA:根据文本框中设置的值在列表框中搜索值

  20. 20

    Excel VBA:根据文本框中设置的值在列表框中搜索值

  21. 21

    使用C#从列表框中的选定项目中获取ValueMember

  22. 22

    在WhereGlause for ArcGis中使用列表框中的多个选定项

  23. 23

    使用jQuery从asp列表框中获取选定项目的计数

  24. 24

    从列表框(ObservableCollection)中删除选定的项目

  25. 25

    从列表框(ObservableCollection)中删除选定的项目

  26. 26

    列表框中的多个默认选定项

  27. 27

    从列表框中的选定项目中删除3行

  28. 28

    从选中的列表框中检索选定的项目?

  29. 29

    从Access中的列表框中提取选定的行

热门标签

归档