Excel Clicking the cell

Hanan Mohammed Alghamdi 26 Reputation points
2022-09-01T15:36:37.78+00:00

Hi...I want when I click on the cell it changes to red and then I click again and it turns green. How is that?

I'll use the file on the iPad later

Microsoft 365 and Office Excel For business Windows
0 comments No comments
{count} votes

Accepted answer
  1. Dillon Silzer 57,826 Reputation points Volunteer Moderator
    2022-09-01T17:35:11.27+00:00

    Hi @Hanan Mohammed Alghamdi

    This can be done with VBA.

    1) You will need the Developer tab

    Go to File > Options > Customize Ribbon > Check off Developer

    237033-image.png

    2) Go to the Developer tab and press Visual Basic

    3) Go to the Sheet or ThisWorkBook and copy in the following code (cited from https://www.mrexcel.com/board/threads/can-you-change-a-cell-color-just-by-clicking-it.407894/):

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)  
    Cancel = True  
    Target.Interior.ColorIndex = 3  
    End Sub  
    
    Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)  
    Cancel = True  
    Target.Interior.ColorIndex = 4  
    End Sub  
    

    237026-image.png

    4) Go back into the Excel spreadsheet and Double Click will turn it red and Right Click will turn it green. (a bit different than your ask, but works well).

    236999-image.png


    If this is helpful please accept answer.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Hanan Mohammed Alghamdi 26 Reputation points
    2023-05-13T09:19:54.7666667+00:00

    تم حل المشكلة. شكرا لمساعدتكم

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.