Enter Text/Characters with a Double-Click of the Mouse

Add to Favorites
Author:
This macro allows you to enter any text or number, that you specify, in a cell on which you double-click. In the example macro below, an X will be entered into any cell on which you double-click. This can be very useful for filling out forms or "ckecking-off" a list of things to do in excel. It is much easier than typing the same thing over and over again in excel. Also, there is a string of text or numbers which you must repeatedly enter, you can use this macro to enter that text or number through the double-click of the mouse.

To change the macro to display what text or numbers you want simply change the "X" in the following line of code to whatever you want; rCell.Value = "X". Also, this macro will only work on a predefined range of cells. This means that you can set it so that if you double-click in certain cells, the text will be entered, but if you double-click elsewhere, no text will be entered into the cell. To change the cells for which this macro will work, change the range of A1:C25 in the following code to whatever cells you want; Set rInt = Intersect(Target, Range("A1:C25")).

Note: If you double-click a cell which already has something in it, this macro will replace the cell's contents with whatever is specified in the macro.

Where to install the macro:  Worksheet

Enter Text/Characters with a Double-Click of the Mouse

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

    Dim rInt As Range
    Dim rCell As Range

    Set rInt = Intersect(Target, Range("A1:C25"))
    If Not rInt Is Nothing Then
        For Each rCell In rInt
            rCell.Value = "X"
        Next
    End If

    Set rInt = Nothing
    Set rCell = Nothing
    Cancel = True

End Sub







Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons 50+ Hours of Instruction 200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Similar Content on TeachExcel
Formula to Count Occurrence of Specific Characters in a Cell
Tutorial: Formula that counts the occurrences of a specific character in a cell in Excel. This tutor...
Sorting Data by Date, Text, or Number in Excel
Tutorial: Sorting Data can be done with a few quick clicks of the mouse. I have used the same data a...
Make a UserForm in Excel
Tutorial: Let's create a working UserForm in Excel. This is a step-by-step tutorial that shows you e...
Run a Macro when a User Does Something in the Worksheet in Excel
Tutorial: How to run a macro when a user does something in the worksheet, everything from selecting ...
How to import Text Files (CSV) into Excel
Tutorial: Text files in CSV format are one of the easiest ways to store and transfer data as it is o...
SUBSTITUTE() Function - Change Specific Text within a Cell in Excel
Tutorial: Change or replace text in a cell with other text - you can replace a single character, num...


How to Install the Macro
  1. Select and copy the text from within the grey box above.

  2. Open the Microsoft Excel file in which you would like the Macro to function.

  3. Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.  Or For other ways to get there, Click Here.

  4. On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.

  5. If the Macro goes in a Module, Click Here, otherwise continue to Step 8.

  6. If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.

  7. If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.

  8. Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.

  9. You are now ready to run the macro.

Tutorial Details
Similar Content
Formula to Count Occurrence of Specific Characters in a Cell
Tutorial: Formula that counts the occurrences of a specific character in a cell in Excel. This tutor...
Sorting Data by Date, Text, or Number in Excel
Tutorial: Sorting Data can be done with a few quick clicks of the mouse. I have used the same data a...
Make a UserForm in Excel
Tutorial: Let's create a working UserForm in Excel. This is a step-by-step tutorial that shows you e...
Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course