+ Reply to Thread
Results 1 to 8 of 8

Macro to select all objects but one and delete

  1. #1
    Registered User
    Join Date
    11-25-2016
    Location
    Warrington
    MS-Off Ver
    2010
    Posts
    60

    Macro to select all objects but one and delete

    Hi all

    I cant seem to get my macro to work, this is what I've got:

    ActiveSheet.DrawingObjects.Select
    ActiveSheet.Shapes.SelectAll
    ActiveSheet.Shapes.Range(Array("Rectangle 14")).Deselect
    Selection.Delete
    Columns("A:X").Select
    Selection.Delete Shift:=xlToLeftAndUp

    I'm getting an error at the section that I am telling the macro to "select all objects" apart from "rectangle 14" rectangle 14 is the button I will use to activate the macro.

    Can anyone help me?

  2. #2
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Macro to select all objects but one and delete

    upload the workbook with the said objects and desired results
    Teach me Excel VBA

  3. #3
    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: Macro to select all objects but one and delete

    Maybe

    Please Login or Register  to view this content.
    Incidentally please note our forum rules about wrapping code in code tags which makes macros easier to read.
    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.

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Macro to select all objects but one and delete

    Hi,

    If you want to avoid a loop you can temporarily hide the object you don't want deleted thus
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  5. #5
    Registered User
    Join Date
    11-25-2016
    Location
    Warrington
    MS-Off Ver
    2010
    Posts
    60

    Re: Macro to select all objects but one and delete

    Firstly, apologies for not wrapping the text, if I'm honest I wanted to wrap it (it looks nicer as well as being easier) but I couldn't figure out where the button was (its the simply # button I have now realised)

    I have attached the workbook to this document to show you what I want, i have some samples in their currently, the worksheet I am editing is called "Data Storage" "rectangle 14" is fixed so that cells don't move it, what I need to happen is when that button is pressed it runs the macro to delete all objects on the page, bar the button, and also reset's the pages size, therefore when you press it and save the file size goes as if going back to "blank"

    I will give your previous macros a go and see if it fixes it.
    Attached Files Attached Files

  6. #6
    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: Macro to select all objects but one and delete

    I don't understand the requirement

    When the shapes other than shape 14 are deleted you have a blank page other than two cells in column A with the word "January", which I presume are redundant.

    Can you add a copy of the sheet showing what it should look like after the shape deletion macro?

  7. #7
    Registered User
    Join Date
    11-25-2016
    Location
    Warrington
    MS-Off Ver
    2010
    Posts
    60

    Re: Macro to select all objects but one and delete

    Quote Originally Posted by Richard Buttrey View Post
    I don't understand the requirement

    When the shapes other than shape 14 are deleted you have a blank page other than two cells in column A with the word "January", which I presume are redundant.

    Can you add a copy of the sheet showing what it should look like after the shape deletion macro?
    So that page is where I will store pictures of the data from the other page, I have another macro that pastes the pictures on the page for me to store for 12 months, or however long I want them.

    the "clear YTD data" button just needs to clear the data on that worksheet leaving it completely blank apart from the macro enabled button on the top right.

    So basically I just want that button to delete all contents on that page, barr the button, but I don't want the page length or file size to remain the size that it is when the data was there.

  8. #8
    Registered User
    Join Date
    11-25-2016
    Location
    Warrington
    MS-Off Ver
    2010
    Posts
    60

    Re: Macro to select all objects but one and delete

    eureka!

    I solved it!

    Please Login or Register  to view this content.

+ 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. Macro to Select and Delete Columns and or Rows
    By HangMan in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-09-2013, 09:40 AM
  2. [SOLVED] macro to select 'all' and delete contents.
    By emilyloz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-30-2013, 09:08 AM
  3. VBA to select all objects in chart
    By manali7120 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-19-2013, 12:25 PM
  4. Macro to delete all objects except charts
    By Mathematicus in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-24-2011, 03:12 PM
  5. Excel 2007 : Select Objects
    By Chrisp in forum Excel General
    Replies: 4
    Last Post: 06-19-2008, 01:42 AM
  6. Need a macro to select and delete records.
    By jeryst in forum Excel General
    Replies: 1
    Last Post: 01-11-2007, 04:25 PM
  7. Macro to Delete Drawing Objects
    By jimmeh in forum Excel General
    Replies: 0
    Last Post: 04-28-2005, 06:15 PM

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