+ Reply to Thread
Results 1 to 4 of 4

Changing cell color

Hybrid View

  1. #1
    Registered User
    Join Date
    08-26-2016
    Location
    england
    MS-Off Ver
    ms office
    Posts
    26

    Changing cell color

    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
    Attached Files Attached Files

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,627

    Re: Changing cell color

    Sheet2 is wrong.
    It should be:

    Sheets("Quotation Form").Range("A44").Interior.ColorIndex = 2

  3. #3
    Registered User
    Join Date
    08-26-2016
    Location
    england
    MS-Off Ver
    ms office
    Posts
    26

    Re: Changing cell color

    Hi Zbor,

    Thanks for responding but it throws up the same error code.

    Kind Regards

  4. #4
    Registered User
    Join Date
    11-01-2012
    Location
    Cairo, Egypt
    MS-Off Ver
    MS Office 2013
    Posts
    76

    Re: Changing cell color

    the sheet is protected ..
    UN-protect it, Then apply the process again ...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Any way to apply a color theme by changing the color of one cell ?
    By KomicJ in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-02-2016, 01:11 PM
  2. Replies: 3
    Last Post: 08-18-2014, 12:47 PM
  3. [SOLVED] Changing fill color of shapes based on changing cell value
    By Stefan1983 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-25-2012, 10:33 AM
  4. Changing a cell's color based on it's color and the value of another cell
    By lorr in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-05-2012, 01:09 PM
  5. changing cell color based on changing values
    By tvonbehren in forum Excel General
    Replies: 2
    Last Post: 09-16-2009, 12:33 PM
  6. Changing Cell Color
    By motown in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-09-2008, 04:52 PM
  7. [SOLVED] Changing cell color
    By Kas in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-14-2005, 05:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1