Moving chart location in VBA

tabbytomo

New Member
Joined
Jun 23, 2016
Messages
18
Hiya, so thanks to some of you I'm 99% done with my pet project! I have only one tiny thing left that I can't for the life of me figure out.

My below code selects a range based on a criteria, copies that range, pastes it into a chart, then exports the chart as a .jpg to a specified folder. However, the charts that are created are getting in the way of some of the subsequent images. Could someone assist with me with how I move the chart out to at least column AM to keep it out the way. Current code below;

VBA Code:
Sub MakeTeamSnapshot(team As Variant)
    Dim PerformanceSheet As Worksheet
    Set PerformanceSheet = Sheets("Flu Database 1")
    Dim sh As Shape
     
    With PerformanceSheet
        .Range("$A$1:$Y$1500").AutoFilter Field:=15, Criteria1:=team
        Dim tmpChart As Chart
        Set sh = PerformanceSheet.Shapes(PerformanceSheet.Shapes.Count)
        Set tmpChart = Charts.Add
                tmpChart.ChartArea.Clear
        tmpChart.Name = "PicChart" & (Rnd() * 10000)
        Set tmpChart = tmpChart.Location(Where:=xlLocationAsObject, Name:=PerformanceSheet.Name)
        tmpChart.ChartArea.Width = 500
        tmpChart.ChartArea.Height = 800
    'Paste range as image to chart
        .Range("A1").CurrentRegion.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
        tmpChart.ChartArea.Select
        tmpChart.Paste
        'Save chart image to file
        Dim fileSaveName As Variant
        fileSaveName = SAVE_FOLDER & Replace$(team, " ", "") & "." & SAVE_FORMAT
          tmpChart.Export Filename:=fileSaveName, FilterName:=SAVE_FORMAT
        'Clean up
        tmpChart.Parent.Delete
    End With

End Sub
 
Last edited:

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Not really following how the charts are getting in the way of subsequent images? The chart code deletes the chart after it is exported to an image file. Do you want to place the top left chart corner at AM row 1? Maybe a bit more info. Dave
 
Upvote 0
Sorry after more testing some of the ranges are so large (say A1:D90) that when the chart is created it sits over part of the range. So when the screenshot happens, you see part of the chart covering part of the range. Just aesthetically displeasing.

I have solved this now though by inserting this line after the lines that define the height and width:

VBA Code:
tempChart.Parent.Left = 2000
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top