With statement

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,913
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Can someone please tell me why this works:

Code:
    Sheet1.Shapes("Button").Select
    
    With Selection
    
        .ShapeRange.Fill.ForeColor.RGB = 12345
    
    End With

but this doesn't:

Code:
    With Sheet1.Shapes("Button")
    
        .ShapeRange.Fill.ForeColor.RGB = 12345
    
    End With

The error message is:

Code:
Object doesn't support this property or method

Thanks
 
Last edited:

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
You want:
Rich (BB code):
    With wksresult.Shapes("Button")
        .Fill.ForeColor.RGB = 12345
    End With

The Selection object is not the same object as is returned by wksresult.Shapes("Button")
 
Last edited:
Upvote 0
Thanks

I thought the general "rule" was to remove the select and selection words.

Usually works for me.
 
Last edited:
Upvote 0
It depends, sometimes that's true, sometimes it isn't - that's why it's a "general" rule
 
Upvote 0
It depends, sometimes that's true, sometimes it isn't - that's why it's a "general" rule

So when the "general" rule fails, should the next step be to start removing properties from the left until it works, in the example above, remove the property ShapeRange?
 
Last edited:
Upvote 0
No, it should be looking in the Locals window and see what object you're actually dealing with and what properties it has
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top