0

I have a similar question to one that has been posted before on this site, I just need to modify how its done a little bit.

Creating Line Chart for each Row using VBA excel (Dynamic Row,Column)

I need to do the exact same thing as above, except I need for my selection to start in cell B4. From B4, it needs to go to the last row and the last column, just like above. Just need to start in B4 instead of A1. I tried to ask this question on that post from above, but someone deleted it for some reason.

1
  • 2
    If the only difference is which cell you want to start in, just change the cell range. Commented Apr 10, 2014 at 19:19

1 Answer 1

2

Why not try the following (swapping out the A1 for B4 in the last column entry). Taking from the excellent answer that @Santosh provided here:

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
Sign up to request clarification or add additional context in comments.

1 Comment

I have tried this, and I see what you are saying, but its not exactly working because I need to start on row B, I wasn't sure how to manipulate the code to be able to do that?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.