Hello,
I hope my request is possible. I need to create a code to go through the data on a spreadsheet and create chart for each product block. There are might be multiple product blocks. I got code to create the first one, but I am pretty bad with loops and have no idea how to make it go through the sheet and create one chart per block of data. Each block has one row identical and it is a header row - the first cell "In Stock?" I need to use information from columns A & B. Below is a code I have for the first block of data:
Sub chart1()
Dim myWorksheet As Worksheet
Dim mySourceData As Range
Dim myChart As Chart
Dim myChartDestination As Range
'identify worksheet containing source data and created bar chart
Set myWorksheet = ThisWorkbook.Worksheets("Overall Summary")
With myWorksheet
'identify source data
Set mySourceData = .Range("A6:B9")
'identify chart location
Set myChartDestination = .Range("J2:N10")
'create bar chart
Set myChart = .Shapes.AddChart(XlChartType:=xlWaterfall, Left:=myChartDestination.Cells(1).Left, Top:=myChartDestination.Cells(1).Top, Width:=myChartDestination.Width, Height:=myChartDestination.Height).Chart
End With
'set source data for created bar chart
myChart.SetSourceData Source:=mySourceData
End Sub
Thanks,
Inna
I hope my request is possible. I need to create a code to go through the data on a spreadsheet and create chart for each product block. There are might be multiple product blocks. I got code to create the first one, but I am pretty bad with loops and have no idea how to make it go through the sheet and create one chart per block of data. Each block has one row identical and it is a header row - the first cell "In Stock?" I need to use information from columns A & B. Below is a code I have for the first block of data:
Sub chart1()
Dim myWorksheet As Worksheet
Dim mySourceData As Range
Dim myChart As Chart
Dim myChartDestination As Range
'identify worksheet containing source data and created bar chart
Set myWorksheet = ThisWorkbook.Worksheets("Overall Summary")
With myWorksheet
'identify source data
Set mySourceData = .Range("A6:B9")
'identify chart location
Set myChartDestination = .Range("J2:N10")
'create bar chart
Set myChart = .Shapes.AddChart(XlChartType:=xlWaterfall, Left:=myChartDestination.Cells(1).Left, Top:=myChartDestination.Cells(1).Top, Width:=myChartDestination.Width, Height:=myChartDestination.Height).Chart
End With
'set source data for created bar chart
myChart.SetSourceData Source:=mySourceData
End Sub
Thanks,
Inna