PDA

View Full Version : Problem changing cell color on button click



LePig
08-26-2016, 05:36 AM
Hi,

I am having problems changing the cell color on button click.

I want the cells to be invisible/white when the file opens but when i click a button for the cell to change color.

Please see code below



Private Sub Workbook_Open()
If ThisWorkbook.Sheets("Quotation Form").Range("A44").Interior.ColorIndex = 15 Then
MsgBox "i am white"
Sheets("Quotation Form").Range("A44").Interior.ColorIndex = 2
Else
End If
End Sub

And then on the sheet with the button the following code

Private Sub CommandButton2_Click()
If ThisWorkbook.Sheets("Quotation Form").Range("A44").Interior.ColorIndex = 2 Then

ThisWorkbook.Sheets("Quotation Form").Range("A44").Interior.ColorIndex = 15
Else

End If
End Sub

It is giving me a

run time error 1004

Application-Defined or object-defined error

Any ideas or help much appreciated.

Thanks in advance

SamT
08-26-2016, 07:38 AM
No ideas. You forgot to say where the error was occurring at.

Try these

Private Sub Workbook_Open()
Sheets("Quotation Form").Range("A44").Interior.ColorIndex = 2
End Sub


Private Sub CommandButton2_Click()
Range("A44").Interior.ColorIndex = 15
End Sub