I have a worksheet named "Summary". Column "A" to column "Q" have variable numbers of data. The number of rows are not fixed(dynamic) for a column. Also Sometimes one or more column are empty or all the cells in a column have missing data.
Now, I want to create a LineMarkers chart from each column (having different number of rows in column "A" to column "Q").The first row is for heading. The VBA should able to recognised the changes made in data and accordingly the chart will also gets updated every time.
I have the following code which take row as range for the chart. If the VBA code can be modified to take column as range for the chart.Thanks
Sub chart()
'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("Summary").Range("A65536").End(xlUp).Row
'Find the last used column
LastColumn = Sheets("Summary").Range("A1").End(xlToRight).Column
'Looping from second row till last row which has the data
For i = 2 To lastRow
'Sheet 2 is selected bcoz charts will be inserted here
Sheets("Summary").Select
'Adds chart to the sheet
Set chrt = Sheets("Summary").Shapes.AddChart.chart
'sets the chart type
chrt.ChartType = xlLineMarkers
'now the line chart is added...setting its data source here
With Sheets("Summary")
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
Now, I want to create a LineMarkers chart from each column (having different number of rows in column "A" to column "Q").The first row is for heading. The VBA should able to recognised the changes made in data and accordingly the chart will also gets updated every time.
I have the following code which take row as range for the chart. If the VBA code can be modified to take column as range for the chart.Thanks
Sub chart()
'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("Summary").Range("A65536").End(xlUp).Row
'Find the last used column
LastColumn = Sheets("Summary").Range("A1").End(xlToRight).Column
'Looping from second row till last row which has the data
For i = 2 To lastRow
'Sheet 2 is selected bcoz charts will be inserted here
Sheets("Summary").Select
'Adds chart to the sheet
Set chrt = Sheets("Summary").Shapes.AddChart.chart
'sets the chart type
chrt.ChartType = xlLineMarkers
'now the line chart is added...setting its data source here
With Sheets("Summary")
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