+ Reply to Thread
Results 1 to 10 of 10

Dynamically Delete Chart ??

  1. #1
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,015

    Dynamically Delete Chart ??

    .
    Please Login or Register  to view this content.
    The above is the portion of existing code that selects a range (after searching and locating a specific term related to the range) and deletes everything in the range,
    then SHIFTS those rows (only the selected cells) up. In most cases, there is other existing data located below the selected area.

    Randomly, Excel is leaving a replacement Chart that doesn't correspond to anything. It just simply appears. Weird !

    So, what is wrong with the existing code ...

    Thanks for your assistance.

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Dynamically Delete Chart ??

    Not sure I immediately see anything wrong with the code other than you don't need the .Select and then the Selection.Delete. That can be combined into one line. Hard to say why you are get a replacement chart when deleting, so maybe a sample is needed.
    HTH
    Regards, Jeff

  3. #3
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,015

    Re: Dynamically Delete Chart ??

    .
    Ok .. I've been doing some deeper research into the existing. It is not doing exactly what I believed.

    Presently the code is not selecting the chart ... which is what I previously believed.

    So ... the primary problem is : How do I select a chart that is in a range of cells that have been dynamically selected (.SELECTION) ... WITHOUT using the chart name ?

    In other words .. whatever chart happens to exist in the selected range ?


    Thanks.

    ps: everything I've located, all specifically name a chart.

  4. #4
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,015

    Re: Dynamically Delete Chart ??

    .
    As depicted in the image, the single correct chart has been selected. I've gotten this far. But I can't get it deleted using either Selection.Delete or Selection.Cut .

    Here is the macro that manages to get the correct chart selected ...

    Please Login or Register  to view this content.
    Here is an image showing the sheet up to the point of the above macro completion. As you can see, only the targeted chart has been selected.

    Chart Select.jpg

  5. #5
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Dynamically Delete Chart ??

    Hi Logit,

    Not sure I have an answer here so I will post to the Calvary for some assistance.

  6. #6
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,015

    Re: Dynamically Delete Chart ??

    .
    Thanks.

    This has me stumped.

  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: Dynamically Delete Chart ??

    Your chart is being selected not because it's within a particular range but because you're looping through all the charts on the sheet.

    The following will of course delete it.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Are you still wanting to only delete if the chart is within 11 rows and 12 columns of the active cell?

    Why the reluctance to use the chart name which would be the usual course of action and far safer?
    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.

  8. #8
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,615

    Re: Dynamically Delete Chart ??

    Fetch the top & left of the range.
    loop through the chartobjects and select the one with top & left within +/- x of the range t/l...?

    ActiveSheet.ChartObjects(N).Delete??
    Ben Van Johnson

  9. #9
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,015

    Re: Dynamically Delete Chart ??

    .
    Or if I can capture the chart name ?

    Yes ... I don't want to delete ALL charts. Just the chart that is located within the selected range.

    Thank you.
    Last edited by Logit; 07-12-2020 at 08:50 PM.

  10. #10
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,015

    Re: Dynamically Delete Chart ??

    .
    Ok ... I believe I have my answer. Need to test it several more times to verify it works.

    A different macro, when the chart is created, writes the Chart Name to a cell that will be covered by the chart.

    Then, when the user executes the macros to delete the table, several other ranges and finally the chart, the following identifies the chart name
    then deletes the chart.

    Please Login or Register  to view this content.
    The above macro utilizes the following Function as well :

    Please Login or Register  to view this content.
    Thank you all for your assistance. Your comments led me to the solution.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Delete columns dynamically keeping the last four to the right
    By gotroots in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-03-2020, 05:10 PM
  2. [SOLVED] Dynamically Delete (Repeated) Title Rows
    By sherylt13 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-02-2018, 10:11 PM
  3. Cannot delete single column dynamically - vba excel 2010
    By Ant.Cameron in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-06-2014, 06:20 AM
  4. Cannot delete single column dynamically - vba excel 2010
    By Ant.Cameron in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 09-26-2014, 09:41 PM
  5. Combine and delete duplicate rows...dynamically
    By crc21 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-01-2014, 11:38 AM
  6. Combine and delete duplicate rows dynamically
    By crc21 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 11-10-2010, 07:28 PM
  7. delete vbcode dynamically
    By ilyaskazi in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-15-2005, 10:05 AM

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