Assigning backgroundcolor to button on form

G

Guest

I have the following code to assign a background color to a button on a
userform.
Set Mycmd = Controls.Add("Forms.CommandButton.1", "COL")
Mycmd.Left = 12
Mycmd.Top = 70
Mycmd.Width = 12
Mycmd.Height = 12
ActiveSheet.Select
Mycmd.BackColor = Range(Cells(1, 1)).Interior.color

This code returns me the error "Method range of _object global failed". When
I change the line Mycmd.BackColor = Range(Cells(1, 1)).Interior.color to
Mycmd.BackColor = Range("A1").Interior.color the codes work just fine.

What is wrong with my code?? As I expect cells(1,1) to be the same as
range("A1").

Furthermore I have to have line activesheet.select in the statement to copy
the colors correctly (when it are colors not from default palette). Does
anyone know why this part of the code should be included?

TIA
 
Z

Zack Barresse

I suspect that "color" should be "colorindex". Was this the case?

Good to see you figured it out though!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top