使用Vlookup的Excel VBA格式化图表系列

时间:2017-02-27 18:58:24

标签: excel-vba charts vlookup vba excel

我是新的VBA用户,我正在尝试根据系列名称设置图表系列的格式。我想使用vlookup来引用系列名称并返回一个定义的MarkerStyle,MarkerForegroundColor,MarkerSize等。我想要这样做,因为我有一个很大的系列名称列表,每个都需要一个独特的标记,我需要制作大量图表。我已经启动了一个代码,但一直收到1004错误:'无法获取WorksheetFunction类的Vlookup属性':

 Sub ChartFormattingVlookup()
    Dim mySeries As Series
    Dim cht As ChartObject
    Dim vbc As Range
    Set vbc = Worksheets("VBAChartFormat").Range("A2:I44")

    For Each cht In ActiveSheet.ChartObjects
        cht.Activate
        For Each mySeries In ActiveChart.SeriesCollection
            With mySeries
                .MarkerSize = Application.WorksheetFunction.VLookup(mySeries, vbc, 7, False)
                .MarkerStyle = Application.WorksheetFunction.VLookup(mySeries, vbc, 6, False)
            End With
        Next mySeries
    Next cht
End Sub

我很感激任何帮助或建议。谢谢!

1 个答案:

答案 0 :(得分:0)

对@Scott Holtzman的跟进发表评论,为什么您的VLookup函数出现错误,也无需Activate cht,然后使用{{1} },只需使用ActiveChart

此外,您应该考虑为For Each mySeries In cht.SeriesCollection的可能失败添加错误操作。

Application.WorksheetFunction.VLookup