Consulting

Results 1 to 2 of 2

Thread: Problem changing cell color on button click

  1. #1
    VBAX Regular
    Joined
    Aug 2016
    Posts
    13
    Location

    Problem changing cell color on button click

    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
    Last edited by SamT; 08-26-2016 at 07:33 AM. Reason: Removed text formatting inside code

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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