Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从某个单元格开始,使用VBA excel(动态行、列)为每行创建折线图_Excel_Vba - Fatal编程技术网

从某个单元格开始,使用VBA excel(动态行、列)为每行创建折线图

从某个单元格开始,使用VBA excel(动态行、列)为每行创建折线图,excel,vba,Excel,Vba,我有一个类似的问题,已经张贴在这个网站上之前,我只需要修改它如何做一点 我需要做与上面完全相同的事情,除了我需要在单元格B4中开始选择。从B4开始,它需要转到最后一行和最后一列,如上所述。只需要从B4开始,而不是A1。我试着在上面的帖子上问这个问题,但有人出于某种原因删除了它。为什么不试试下面的内容(在最后一列条目中将A1替换为B4)。从@Santosh提供的优秀答案中可以看出: 如果唯一的区别是要从哪个单元格开始,只需更改单元格范围。我已经尝试过了,我知道你在说什么,但它并不完全有效,因为我

我有一个类似的问题,已经张贴在这个网站上之前,我只需要修改它如何做一点

我需要做与上面完全相同的事情,除了我需要在单元格B4中开始选择。从B4开始,它需要转到最后一行和最后一列,如上所述。只需要从B4开始,而不是A1。我试着在上面的帖子上问这个问题,但有人出于某种原因删除了它。

为什么不试试下面的内容(在最后一列条目中将A1替换为B4)。从@Santosh提供的优秀答案中可以看出:


如果唯一的区别是要从哪个单元格开始,只需更改单元格范围。我已经尝试过了,我知道你在说什么,但它并不完全有效,因为我需要从B行开始,我不确定如何操作代码才能做到这一点?
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