VBA用于根据表中的行数确定图表types

我试图写一些VBA,它会根据表中的行数自动生成某种types的图表。 我正在使用一个IF循环,如下所示,基于一个lastrowvariables。 我已经通过使用F8代码滚动和lastrowvariables注册正确,但这不会影响出现的图表types – 它总是一个列图,我猜是默认设置…任何帮助极大的赞赏。

代码段:

With Worksheets("TableScores") lastrow = .Cells(Rows.Count, "A").End(xlUp).Row ActiveSheet.Shapes.AddChart.Select If lastrow <= 3 Then .ChartType = xlBar Else: .ChartType = xlLine End If End with 

(未testing)

 With Worksheets("TableScores") Dim cht as Chart Set cht = ActiveSheet.Shapes.AddChart() lastrow = .Cells(Rows.Count, "A").End(xlUp).Row If lastrow <= 3 Then cht.ChartType = xlBar Else cht.ChartType = xlLine End If End with