Move chart on worksheet to variable location

JohnZ1156

Board Regular
Joined
Apr 10, 2021
Messages
157
Office Version
  1. 2021
Platform
  1. Windows
I have a chart on my worksheet that I want to move to a location based on a variable.
I want to move the chart to column N at the row number in variable r.
So, kinda, cell Nr?

VBA Code:
Sub MoveChart()
    Dim r As Integer

    Range("A1048576").End(xlUp).Select
    ActiveCell.Offset(-25, 0).Select
    Application.Goto ActiveCell, Scroll:=True
    r = ActiveCell.Row

    With ActiveSheet
    .ChartObjects(1).Top = .Range("n8129").Top
    .ChartObjects(1).Left = .Range("n8129").Left
    End With
    
    ActiveCell.End(xlDown).Select
    ActiveCell.Offset(1, 0).Select
    
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Maybe you can use something like this...
VBA Code:
Sub MoveChart()

    Dim r As Integer

    Range("A1048576").End(xlUp).Select
    ActiveCell.Offset(-25, 0).Select
    Application.Goto ActiveCell, Scroll:=True
    r = ActiveCell.Row
    With ActiveSheet
        .ChartObjects("Chart 1").Chart.Parent.Cut
        .Range("N" & r).Activate
        .Paste
    End With
    ActiveCell.End(xlDown).Select
    ActiveCell.Offset(1, 0).Select
   
End Sub
 
Upvote 0
How about
VBA Code:
    With ActiveSheet
    .ChartObjects(1).Top = .Range("n" & r).Top
    .ChartObjects(1).Left = .Range("n" & r).Left
    End With
 
Upvote 0
Maybe you can use something like this...
VBA Code:
Sub MoveChart()

    Dim r As Integer

    Range("A1048576").End(xlUp).Select
    ActiveCell.Offset(-25, 0).Select
    Application.Goto ActiveCell, Scroll:=True
    r = ActiveCell.Row
    With ActiveSheet
        .ChartObjects("Chart 1").Chart.Parent.Cut
        .Range("N" & r).Activate
        .Paste
    End With
    ActiveCell.End(xlDown).Select
    ActiveCell.Offset(1, 0).Select
  
End Sub
Thanks for your help.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,305
Members
449,079
Latest member
juggernaut24

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