从某个单元格开始使用VBA excel(dynamic行,列)为每个行创build折线图

我有一个类似的问题,在这个网站上发布之前,我只需要修改它是如何做一点点。

使用VBA excel(dynamic行,列)为每个行创build折线图

我需要做与上面完全一样的东西,除了我需要我的select开始在单元格B4。 从B4开始,需要到上一行和最后一列,就像上面一样。 只需要在B4而不是A1开始。 我试图从上面的这个post提出这个问题,但有人删除它出于某种原因。

为什么不尝试以下(在最后一列条目中将B4的A1换出)。 从@Santosh 在这里提供的优秀答案中拿出:

Sub main() 'variable declaration Dim i As Long Dim LastRow As Long Dim LastColumn As Long Dim chrt As Chart 'Find the last used row LastRow = Sheets("Sheet1").Range("A65536").End(xlUp).Row 'Find the last used column - this will be the place that you start, which is in cell B4 LastColumn = Sheets("Sheet1").Range("B4").End(xlToRight).Column 'Looping from second row till last row which has the data For i = 2 To LastRow 'Sheet 2 is selected because the charts will be inserted here Sheets("Sheet2").Select 'Adds chart to the sheet Set chrt = Sheets("Sheet2").Shapes.AddChart.Chart 'sets the chart type chrt.ChartType = xlLine 'now the line chart is added...setting its data source here With Sheets("Sheet1") chrt.SetSourceData Source:=.Range(.Cells(i, 1), .Cells(i, LastColumn)) End With 'Left & top are used to adjust the position of chart on sheet chrt.ChartArea.Left = 1 chrt.ChartArea.Top = (i - 2) * chrt.ChartArea.Height Next End Sub