+ Reply to Thread
Results 1 to 22 of 22

Format selected object

  1. #1
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Format selected object

    I have some inserted rectangles on my worksheet,can I make a macro to fill the selected rectangle with a black fill color? I got the rectangle from shapes.
    Last edited by zplugger; 12-17-2018 at 03:51 PM.

  2. #2
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: Format selected object

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Re: Format selected object

    Thank you, I have 50 rectangle shapes on the sheet and only want to fill the selected one?

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Format selected object

    You could just use:

    Please Login or Register  to view this content.
    Rory

  5. #5
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Re: Format selected object

    Getting error run time 438.

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Format selected object

    What does:

    Please Login or Register  to view this content.
    show if you add it to the start of the code.

  7. #7
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Re: Format selected object

    Box with Range

  8. #8
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Format selected object

    Then you didn't select a rectangle before running the code.

  9. #9
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Re: Format selected object

    I did select the rectangle,not sure its in a certain range. Seems like its just a object.

  10. #10
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Format selected object

    If Typename(selection) returns Range, then you have one or more cells selected, not a rectangle, which would explain the 438 error.

  11. #11
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Re: Format selected object

    If I record a macro on one of the rectangles it works,I would like it to do it to any selected rectangle on the sheet if possible.

    Please Login or Register  to view this content.

  12. #12
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Format selected object

    The code I posted will work as long as you select a rectangle first. If you mean something else by "any selected rectangle", can you please clarify what?

  13. #13
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Re: Format selected object

    Trying to attach a sample workbook, can't get it to download. I can not get the code you posted to work.

  14. #14
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Re: Format selected object

    Here is a example
    Attached Files Attached Files

  15. #15
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Format selected object

    Try assigning this code to all your shapes
    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Re: Format selected object

    still geeting run time error

  17. #17
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Format selected object

    Try this file, all you need to do is click the rectangle.
    Attached Files Attached Files

  18. #18
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Re: Format selected object

    Sorry, I get it now. I think I can make this work OK. Was hoping to use a commandbutton to change selected shape.

  19. #19
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Re: Format selected object

    when I hoover over shape I get 4 arrows,on your example I get a hand?

  20. #20
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Format selected object

    The problem with using a button, is that as soon as you click the button, the button is then selected not the shape.
    You will get the hand symbol because there is a macro assigned to the shape.

  21. #21
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Re: Format selected object

    O I see now, Thank You for all your help,good to learn different stuff.

  22. #22
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Format selected object

    You're welcome & thanks for the feedback

+ 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] Keep object selected while performing another action/selection
    By AJB611 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-19-2017, 07:20 AM
  2. [SOLVED] How to get userform's selected object name/value/caption without handler
    By Kalithro in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-23-2015, 08:30 PM
  3. [SOLVED] Drawing object to change color when selected
    By colarguns in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-15-2014, 09:17 PM
  4. [SOLVED] How do I unselect an object once I have selected it in VBA?
    By redsab in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-19-2013, 10:38 PM
  5. continue after object button has been selected
    By PeterYenroc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-14-2011, 03:11 AM
  6. Excel 2007 : Move Object based on Selected Cell?
    By NewYears1978 in forum Excel General
    Replies: 4
    Last Post: 03-23-2010, 10:49 PM
  7. object selected on a chart
    By Anet in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2005, 02:06 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