VBA Excel创build迷你图

在引用为“Section3”的合并单元格中创buildSparkline。 我要为Sparkline图表引用的数据位于名为“TBLCOL3”的字段中。

<Sub Macro14() Dim ws As Worksheet Dim i As Integer Dim rng3 As Range Dim rng4 As Range Set ws = ActiveSheet i = 3 Set rng3 = ActiveSheet.Range("Section" & i) Set rng4 = ActiveSheet.Range("TBLCOL" & i) rng3.SparklineGroups.Add Type:=xlSparkLine, SourceData:=CStr(rng4.Address) Selection.SparklineGroups.Item(1).SeriesColor.ThemeColor = 5 Selection.SparklineGroups.Item(1).SeriesColor.TintAndShade = -0.499984740745262 Selection.SparklineGroups.Item(1).Points.Negative.Color.ThemeColor = 6 Selection.SparklineGroups.Item(1).Points.Negative.Color.TintAndShade = 0 Selection.SparklineGroups.Item(1).Points.Markers.Color.ThemeColor = 5 Selection.SparklineGroups.Item(1).Points.Markers.Color.TintAndShade = - _ 0.499984740745262 Selection.SparklineGroups.Item(1).Points.Highpoint.Color.ThemeColor = 5 Selection.SparklineGroups.Item(1).Points.Highpoint.Color.TintAndShade = 0 Selection.SparklineGroups.Item(1).Points.Lowpoint.Color.ThemeColor = 5 Selection.SparklineGroups.Item(1).Points.Lowpoint.Color.TintAndShade = 0 Selection.SparklineGroups.Item(1).Points.Firstpoint.Color.ThemeColor = 5 Selection.SparklineGroups.Item(1).Points.Firstpoint.Color.TintAndShade = _ 0.399975585192419 Selection.SparklineGroups.Item(1).Points.Lastpoint.Color.ThemeColor = 5 Selection.SparklineGroups.Item(1).Points.Lastpoint.Color.TintAndShade = _ 0.399975585192419 End Sub> 

我正在使用i = 3,因为这是我将创build的循环的基础。 我已经创build了遍历每个表的代码,并在我的表的右侧创build一个合并的单元格2列,将合并的单元格命名为“Section”&i。 然后在我的表中find第三个数据列,并将其命名为“TBLCOL”&i。

这是难题的最后一块 – 任何反馈将不胜感激。 上面的代码返回全局失败错误消息。 我知道这对应于variables引用,但我无法自行解决。

编辑:修改为第一个评论和添加格式在“loggingmacros”