Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Apr 2007
    Location
    Lancashire, United Kingdom
    Posts
    264
    Thanks
    32
    Thanked 5 Times in 5 Posts

    How do I position graphs next to a cell in VB?

    I have macro which builds a bunch of tables and then produces graphs. I want to position the graphs next to particular cells. When I look at the code which moves graphs (using record macro and look at the results), it's all relative stuff. I want it absolute.

    Is this possible?

    Alan

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts
    You are not very specific in your request. But here is a way to put the top left corner of a chart object named "Chart 1" onto the right side top of cell E21 of the activesheet. Adapt as desired. If you need specific details, you will need to make a more specific request.

    Code:
      Dim shp As Shape
      With ActiveSheet
        Set shp = .Shapes("Chart 1")
        With .Range("e21")
          shp.Top = .Top
          shp.Left = .Left + .Width
        End With
      End With
    Steve

  3. The Following User Says Thank You to sdckapr For This Useful Post:

    alan sh (2014-04-17)

  4. #3
    3 Star Lounger
    Join Date
    Apr 2007
    Location
    Lancashire, United Kingdom
    Posts
    264
    Thanks
    32
    Thanked 5 Times in 5 Posts
    That looks good. I'll try it.

    Sorry if I was a bit vague. I think you caught what I meant though.

    Cheers

    Alan

  5. #4
    3 Star Lounger
    Join Date
    Apr 2007
    Location
    Lancashire, United Kingdom
    Posts
    264
    Thanks
    32
    Thanked 5 Times in 5 Posts
    That works fine. Thanks.

  6. #5
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts
    Glad I could help!

    Steve

  7. #6
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,631
    Thanks
    115
    Thanked 645 Times in 589 Posts
    Alan,

    You can have something a bit more generic and versatile to move any chart object by changing the parameters sent to the subroutine by your macro. you could easily loop the macro call changing the parameters with looped values, ex: MoveChart n, Cells(20, n*10). The following parameters will place the chart directly below your chart series values if they are from A1 to A20.

    Code:
    Public Sub mysub()
    
    '---your code----
    
    MoveChart 1, Range("A20") 'CHANGE THE PARAMETER SENT TO MoveChart
    
    '---your code----
    
    End Sub
    Code:
    Public Sub MoveChart(chrt As Integer, rng As Range)
    With ActiveSheet.ChartObjects(chrt)
    .Left = rng.Left
    .Top = rng.Top + rng.Height
    End With
    End Sub
    chart1.png
    Last edited by Maudibe; 2014-04-18 at 18:44.

  8. The Following User Says Thank You to Maudibe For This Useful Post:

    alan sh (2014-04-22)

  9. #7
    3 Star Lounger
    Join Date
    Apr 2007
    Location
    Lancashire, United Kingdom
    Posts
    264
    Thanks
    32
    Thanked 5 Times in 5 Posts
    Thanks. I like that idea as well. I'll play tomorrow.

    Alan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •