+ Reply to Thread
Results 1 to 20 of 20

Moving down a chart when inserting rows

  1. #1
    Registered User
    Join Date
    11-03-2009
    Location
    Methylane
    MS-Off Ver
    Excel 2003
    Posts
    23

    Moving down a chart when inserting rows

    I've been inserting some rows in some sheets and everything is sound... Until I meet a chart! Charts in general are terrain I yet have to explore (and will be coming Monday)...

    I insert a row like this:
    Please Login or Register  to view this content.
    Works like a charm, it keeps formatting and the dreaded merged cells where I need to keep them, but! Say it inserts 20 rows, but it encounters a chart, the rows keep getting inserted, but the chart isn't moved down accordingly!
    Last edited by ctor; 11-09-2009 at 09:11 AM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Moving down a chart when inserting rows

    Hi,

    Rather than shifting cells, (which is what you are doing as opposed to inserting rows), why don't you insert rows instead. That way your chart will move automatically.
    e.g.
    Please Login or Register  to view this content.
    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    11-03-2009
    Location
    Methylane
    MS-Off Ver
    Excel 2003
    Posts
    23

    Re: Moving down a chart when inserting rows

    Inserting an entire row is not an option due to certain styling in other columns.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Moving down a chart when inserting rows

    If you are talking about the chart object shape not moving with insertion then check the Move & Size properties of the chart.

    Note the chart will only be affected if it is position within the range that is changing.
    Cheers
    Andy
    www.andypope.info

  5. #5
    Registered User
    Join Date
    11-03-2009
    Location
    Methylane
    MS-Off Ver
    Excel 2003
    Posts
    23

    Re: Moving down a chart when inserting rows

    The rows I'm shifting are above the chart, after a few rows it comes across it and though new rows get shifted in, the chart remains at its position
    I was expecting it to shift down accordingly ;(

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Moving down a chart when inserting rows

    If I place a chart in row 10 across C:H columns. I can then insert cells in the range C9:H9 and the chart object moves down.

    Can you post example of your non moving chart?

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Moving down a chart when inserting rows

    Hi,

    One way would be as follows.
    Name a cell within the range you are moving 'Anchor'
    Make a note of the number of rows and columns that the chart is offset.

    Now use the following where r & c in the .Offset are the constants for the offset.

    Please Login or Register  to view this content.
    HTH

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Moving down a chart when inserting rows

    Richard, not sure I completely follow but rather than copy/paste/delete the chart when not just more it?

    Please Login or Register  to view this content.
    Also the paste will cause the name of the chart to change every time.

  9. #9
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Moving down a chart when inserting rows

    Hi Andy,

    I thought about that but wouldn't you have to work out where the top of the chart should be located with reference to the sum of the pixel count for all the rows down to the new location? i.e. how would you calculate the .Top?

    That seemed to be more effort but I'd welcome your comment.


    Regards
    Last edited by Richard Buttrey; 11-06-2009 at 12:34 PM.

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Moving down a chart when inserting rows

    You would indeed need to know where the chart was to be positioned. Just as you would when cutting and pasting.

    The .Top changes the position of the chart.

  11. #11
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Moving down a chart when inserting rows

    Ahh! I've just twigged. I see what you mean.

    Incidentally, when copying and pasting a chart it seems that the copied version of the chart has the same name as the original. How can that be? When the named chart is deleted it deletes the original version, or it did when I tried it and leaves the copy.

    I'm slightly puzzled by this.

    Rgds
    Last edited by Richard Buttrey; 11-06-2009 at 12:58 PM.

  12. #12
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Moving down a chart when inserting rows

    which version of xl gave the copied chart the same name.

    I tested in xl2003, which did not.

  13. #13
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Moving down a chart when inserting rows

    Andy,

    xl2007. I first noticed this a couple of months ago with another workbook and didn't think too much about it at the time.

    Regards

  14. #14
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Moving down a chart when inserting rows

    Do you have SP2 for office installed?
    My xl2007 version increments the chart index when done manually or with code.

  15. #15
    Registered User
    Join Date
    11-03-2009
    Location
    Methylane
    MS-Off Ver
    Excel 2003
    Posts
    23

    Re: Moving down a chart when inserting rows

    Sorry for the late response guys.
    I made a small impression of my situation.

    The real life situation is a bit more complicated though, there are several chart objects on a few different worksheets in this workbook.
    What I'm trying to accomplish is a generic as possible solution.

    Inserting an entire new row certainly works, but that's not the correct solution for this case.
    I'm looking for a method to insert/shift rows into the outlined region, and by doing so the chart should move down. Inserting an entire row is (in the real life situation) no satisfactory solution.
    Attached Files Attached Files
    Last edited by ctor; 11-09-2009 at 06:48 AM.

  16. #16
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Moving down a chart when inserting rows

    This works for me.
    Please Login or Register  to view this content.
    If you only want the cells that are actually bordered, A4:J4, then you will need to adjust the position/size of the chart object so it is all contained within those columns, as currently it over hangs column K

  17. #17
    Registered User
    Join Date
    11-03-2009
    Location
    Methylane
    MS-Off Ver
    Excel 2003
    Posts
    23

    Re: Moving down a chart when inserting rows

    If you only want the cells that are actually bordered, A4:J4, then you will need to adjust the position/size of the chart object so it is all contained within those columns, as currently it over hangs column K
    Yeah, but I'm not able to do that on every sheet, due to the layout this template is blessed with.
    The project has some... nasties
    I've worked it out using the IncrementTop property of the Shape class.
    I just added an optional parameter to my shift method, if it's set to true then it iterates over the shapes in de Shapes collection and moves the shape 12.75 * the number of rows that need to be inserted/shifted in.
    Damn this code is in need of some refactoring. AGAIN!
    Last edited by ctor; 11-09-2009 at 08:47 AM.

  18. #18
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Moving down a chart when inserting rows

    Hi Andy,

    Yes I have SP2 installed.

    You are right in that if you accept the default chart names, i.e. Chart1, Chart2 etc. each time you copy and paste a chart then the copy is incremented by 1.

    However when you name a chart, then copy and paste it, the copy seems to have the same name. When I select and delete the original the copy remains with the original name.

    Somehow it doesn't seem right that two charts, (or two anythings for that matter) can have the same name. Fortunately I've not encountered any problems with this but it just seems odd.

    Regards

  19. #19
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Moving down a chart when inserting rows

    When chart is named via code and copied I can reproduce.

    That is a nasty problem just waiting to catch someone out!

  20. #20
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Moving down a chart when inserting rows

    Thanks Andy,

    It's nice to have your confirmation and know it's not just me!

    Rgds

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1