LePig
08-30-2016, 03:14 AM
Hi,
I am trying to change the color of a cell on a specific sheet when an action occurs either on button click on on open.
However it keeps throwing out a 1004 error code
Application-defined or object defined error.
The code exists in the main workbook
If ThisWorkbook.Sheets("Quotation Form").Range("A44").Interior.ColorIndex = 15 Then
MsgBox "i am white"
Sheet2.Range("A44").Interior.ColorIndex = 2
'Sheets("Quotation Form").Range("A42").Interior.ColorIndex = 2
'ThisWorkbook.Sheets("Quotation Form").Range("B44").Font.ColorIndex = 2
'Sheets("Quotation Form").Range("B42").Font.ColorIndex = 2
Else
End If
The confusing part is that it recognises the initial if statement because it will print the MsgBox but then finds fault with the part where i ask it to link to the specific spreadsheet. As you can see from the exert above i have tried a few different variations of linking to the sheet.
My spreadsheet contains lots of other code so to troubleshoot i tried to change the cell colour in a new spreadsheet project and the above code and it works fine.
Any ideas why it is not working would be greatly appreciated.
I find it confusing that the if statement can find the requested sheet but the statements inside cannot?
Thank you in advance
Many thanks
I am trying to change the color of a cell on a specific sheet when an action occurs either on button click on on open.
However it keeps throwing out a 1004 error code
Application-defined or object defined error.
The code exists in the main workbook
If ThisWorkbook.Sheets("Quotation Form").Range("A44").Interior.ColorIndex = 15 Then
MsgBox "i am white"
Sheet2.Range("A44").Interior.ColorIndex = 2
'Sheets("Quotation Form").Range("A42").Interior.ColorIndex = 2
'ThisWorkbook.Sheets("Quotation Form").Range("B44").Font.ColorIndex = 2
'Sheets("Quotation Form").Range("B42").Font.ColorIndex = 2
Else
End If
The confusing part is that it recognises the initial if statement because it will print the MsgBox but then finds fault with the part where i ask it to link to the specific spreadsheet. As you can see from the exert above i have tried a few different variations of linking to the sheet.
My spreadsheet contains lots of other code so to troubleshoot i tried to change the cell colour in a new spreadsheet project and the above code and it works fine.
Any ideas why it is not working would be greatly appreciated.
I find it confusing that the if statement can find the requested sheet but the statements inside cannot?
Thank you in advance
Many thanks