为每个合并单元格下方的列dynamic绘制单独的图表

我应该在下面的代码范围内做什么修改,以便代码将search每个唯一的合并单元格,并绘制特定部门合并单元格下面的列图表。 我可以有不同的合并单元格下的dynamic列数(如不同月数)。 此外,部门的数量将是dynamic的。 所有build议在这个代码的其他更改。 (我已经在代码中使用了'ColumnMax',因为它将被用于长距离,并且将被用于代替'7')

请在这里find我的数据与示例图表http://bit.ly/1dROvFs 。 我希望代码dynamic地为所有部门绘制相同types的图表。

代码如下:

Sub Charts() Dim rChart1 As Range Dim iColumn As Long Dim lastCol4 As Long Dim currentrcol As Long Dim cht1 As Chart lastCol4 = ActiveSheet.Cells(2, ActiveSheet.Columns.Count).End(xlToLeft).Column Const StrtRow As Long = 1 Const EndRow As Long = 7 Dim ColumnMax As Long ColumnMax = lastCol4 - 4 With ActiveSheet Set rChart1 = .Range(.Cells(StrtRow, "A"), .Cells(EndRow, "A")) For iColumn = 2 To 7 Step 2 Set rChart1 = Union(rChart1, .Range(.Cells(StrtRow, iColumn), .Cells(EndRow, iColumn))) Next Set cht1 = .Shapes.AddChart.Chart With cht1 .Parent.Left = .Parent.Left - .Parent.Width / 2 .ChartType = xlColumnClustered .SetSourceData rChart1, xlColumns End With End With End Sub