I have inserted a bunch of rectangle shapes within my spreadsheet. They are called:

Rectangle 1 thru Rectangle 172

Is there some code I could use to change the fill and line color? I would assign the code to another button that would change it.

link|improve this question

you want to change ALL at once, or one based upon it being selected? If so you could by-pass using a button and just change color when clicking on the rectangle you want – datatoo Sep 29 '11 at 19:58
feedback

1 Answer

see if this will adapt to your needs make each rectangle call this macro

Sub doRectChange()
 Dim c
  c = Application.Caller
 MsgBox (c)
  With ActiveSheet.Shapes(c)
   .Fill.ForeColor.SchemeColor = 3
   .Fill.Transparency = 0#
   .Line.Weight = 3#
   .Line.DashStyle = msoLineSolid
   .Line.Style = msoLineSingle
   .Line.Transparency = 0#
   .Line.Visible = msoTrue
   .Line.ForeColor.SchemeColor = 6
  End With
 End Sub

Here is an alternative Of course your button numbers may be different so adjust for that.

Sub allRectanglesColor()
Dim c
Dim color
c = Application.Caller
'MsgBox (c)
Select Case c
Case "Button 1"
color = 10
Case "Button 2"
color = 12
Case "Button 3"
color = 17
End Select
ActiveSheet.Rectangles.Select
 With Selection.ShapeRange
    .Fill.Visible = msoTrue
    .Fill.Solid
    .Fill.ForeColor.SchemeColor = color
 End With
End Sub
link|improve this answer
I have three buttons that are labled "Blue", "Green", & "Red". When I click each button I would like for the color of all rectangles to change to that color. – Mike Sep 30 '11 at 16:10
It's not the buttons that change colors, it's the 172 rectangles after I click the buttons. Thanks – Mike Sep 30 '11 at 19:42
The second code version I provided, will change the color of all rectangles based upon the button selected. The buttons in my sample assumed "red" is "Button 1", "blue" is "Button 2", "green" is "Button 3" – datatoo Sep 30 '11 at 20:52
assign the same macro to each of the button – datatoo Sep 30 '11 at 22:08
was this not what you were trying to achieve? It should be simple to accomplish what you wanted @Mike – datatoo Oct 17 '11 at 16:17
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.