View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ian Digby[_3_] Ian Digby[_3_] is offline
external usenet poster
 
Posts: 15
Default Change buttoncolor on button on a sheet from VBA

When you reference "button1" as in your first example which works, you are referencing an object. In the non-working other examples you are referencing text, which you can't set to a value.

Try (if the buttons are on a form)
<formname.Controls("Button" & cstr(I))

or if they are on a sheet:
<sheetname.Controls("Button" & cstr(I))

"akyhne" wrote:

Button1.BackColor = &H8000& works ok, but if I make a loop like this

for I = I to 10
if <argument true then
("Button" & cstr(I)).BackColor = &H8000
end if
next

I get this error: Expected : Linenumber or Label or statement or end of statement
how should I call my Button
I tried with:
sheets("sheet1"). ("Button" & cstr(I)).BackColor = &H8000
sheet1. ("Button" & cstr(I)).BackColor = &H8000
activesheet. ("Button" & cstr(I)).BackColor = &H8000
... and a lot of others