How to Change Cell Value by Clicking on It in Excel

If we want to change cell color by clicking on it, we can implement this via editing VBA code. Don’t be afraid of code editing, this article will show you some short VBA codes directly for changing cell color by double clicking/right clicking on it, you can just copy and paste them into VBA code editing pane. This article will also show you the VBA code for highlighting cells by select them.

Method 1: Change Cell Value by Double Clicking on It


Step 1: On current visible worksheet, right click on sheet name tab to load Sheet management menu. Select View Code, Microsoft Visual Basic for Applications window pops up.

Or you can enter Microsoft Visual Basic for Applications window via Developer->Visual Basic. You can also press Alt + F11 keys simultaneously to open it.

Step 2: In Microsoft Visual Basic for Applications window, enter below code in pane:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    Cancel = True

    Target.Interior.Color = vbBlue

End Sub

Step 3: Save VBA code and quit Microsoft Visual Basic for Applications.

Change Cell Value by Clicking on It 1

Step 4: Try to double click on a cell. Verify that cell background color is filled with blue.

Change Cell Value by Clicking on It 2

Method 2: Change Cell Value by Right Clicking on It


Step 1: Enter below code in Microsoft Visual Basic for Applications:

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)

    Cancel = True

    Target.Interior.Color = vbGreen

End Sub

See screenshot below:

Change Cell Value by Clicking on It 3

Step 2: This time right click on a cell. Verify that cell is changed to green.

Change Cell Value by Clicking on It 4

Method 3: Highlight Cells If Cells Are Selected


Step 1: Enter below code in Microsoft Visual Basic for Applications:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    With Target

        .Worksheet.Cells.FormatConditions.Delete

        .FormatConditions.Add xlExpression, , "TRUE"

        .FormatConditions(1).Interior.Color = vbYellow

    End With

End Sub

See screenshot below:

Change Cell Value by Clicking on It 5

Step 2: Select a range of cells. Verify that cells are filled with yellow.

Change Cell Value by Clicking on It 6

 

Related Posts

Find and Replace Multiple Values

This post will guide you how to find and replace multiple values at once with VBA macro or using formula  in Excel. How do I make multiple find and replace in Excel. Suppose that you have a few cells containing ...

VBA Macro For VLOOKUP From Another Sheet

In the previous post, you should know that how to fix or remove the #N/A error when using VLOOKUP formula to lookup value from another sheet. And this post will show you how to use VBA code to vlookup data ...

How To Insert Comments in Protected Worksheet in Excel

This post will show you how to allow comments in a protected worksheet in Excel. You can easily to insert comments into cells in a normal worksheet in Excel, but if want to insert a comment in a worksheet that ...

How To Convert Text to Upper Cases(Using VBA) in Excel

This post will show you how to switch from lower case to upper case in Excel. and I am going to show you two different ways of converting text to upper cases using formula or VBA macro in Excel 2013,Excel ...

How To Hide Every Other Row in Excel (Using VBA)

This post will show you how to hide alternate rows or columns in Excel or how to hide every third, fourth, fifth row or column in Excel. If you want to hide every other row in your current worksheet, how ...

Sidebar