I have code that creates multiple charts on a single worksheet. The number of charts varies based upon filter criteria applied by the user. I added code to apply page breaks and it works fine on my PC and with my printer. However, when testing the code last week at the customer's premise, I encountered problems with the page breaks due to different printer type. The code will be used by about 30 Account Managers and they will have many different printer types.
I am trying to adjust the chart size and location based upon cell values once the charts have been created.
I am trying to use variables for the chart object, the worksheet and the cells to manage the fact the number of charts varies.
Here is the code I am attempting to use. I found the basics for this code in another MrExcel post and tried to modify it to use multiple variables.
I realize (being a relative VBA novice that I could possibly accomplish when the charts are created using .Location but I am not familiar with how to use that feature.
' Adjust Chart Position by Row rather that Pixel to support accurate Page Breaks
Dim x As Long
Dim ChtObj As ChartObject
Dim ChartSheet As Worksheet
Sheets("Summary Charts").Select
Set ChartSheet = ActiveSheet
TopPos = 6
For Each ChtObj In ActiveSheet.ChartObjects
BottomPos = TopPos + 19
With ChtObj.Chart
.Shapes(ChtObj).Left = ChartSheet.Cells(TopPos, 1).Left
.Shapes(ChtObj).Top = ChartSheet.Cells(TopPos, 1).Top
.Shapes(ChtObj).Height = ChartSheet.Range("I" & TopPos & ":I" & BottomPos).Height
.Shapes(ChtObj).Width = ChartSheet.Range("A" & TopPos & ":I" & BottomPos).Width
End With
Next ChtObj
I get a "Runtime Error 5, Invalid call or procedure on the first .Shapes line.......
.Shapes(ChtObj).Left = ChartSheet.Cells(TopPos, 1).Left
Once this portion of the code works properly, I will add code to enter Page Breaks every x number of Rows
Can anyone help me to get this working properly?
I am trying to adjust the chart size and location based upon cell values once the charts have been created.
I am trying to use variables for the chart object, the worksheet and the cells to manage the fact the number of charts varies.
Here is the code I am attempting to use. I found the basics for this code in another MrExcel post and tried to modify it to use multiple variables.
I realize (being a relative VBA novice that I could possibly accomplish when the charts are created using .Location but I am not familiar with how to use that feature.
' Adjust Chart Position by Row rather that Pixel to support accurate Page Breaks
Dim x As Long
Dim ChtObj As ChartObject
Dim ChartSheet As Worksheet
Sheets("Summary Charts").Select
Set ChartSheet = ActiveSheet
TopPos = 6
For Each ChtObj In ActiveSheet.ChartObjects
BottomPos = TopPos + 19
With ChtObj.Chart
.Shapes(ChtObj).Left = ChartSheet.Cells(TopPos, 1).Left
.Shapes(ChtObj).Top = ChartSheet.Cells(TopPos, 1).Top
.Shapes(ChtObj).Height = ChartSheet.Range("I" & TopPos & ":I" & BottomPos).Height
.Shapes(ChtObj).Width = ChartSheet.Range("A" & TopPos & ":I" & BottomPos).Width
End With
Next ChtObj
I get a "Runtime Error 5, Invalid call or procedure on the first .Shapes line.......
.Shapes(ChtObj).Left = ChartSheet.Cells(TopPos, 1).Left
Once this portion of the code works properly, I will add code to enter Page Breaks every x number of Rows
Can anyone help me to get this working properly?