Enter Text/Characters with a Double-Click of the Mouse
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
How to Install the Macro
- Select and copy the text from within the grey box above.
- Open the Microsoft Excel file in which you would like the Macro to function.
- Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.
Or For other ways to get there, Click Here.
For Excel Versions Prior to Excel 2007
Go to Tools > Macros > Visual Basic Editor
For Excel 2007
Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic
- 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.
- If the Macro goes in a Module, Click Here, otherwise continue to Step 8.
- Go to the menu at the top of the window and click Insert > Module
- Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
- Go to Step 8.
- If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Go to Step 8.
- If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
- Go to Step 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.
- You are now ready to run the macro.
Similar Helpful Excel Resources
I have installed Office Student & Teacher Edition 2003 on two machines - both
running XP Professional. On both computers I have optical wheel mouses (one
MS, one Logitech) with the wheel button set for double-click. However, on
either machine the double-click does not work when trying to open workbooks
in Excel 2003 (or documents in Word 2003 for that matter). The filename is
just highlighted, but if I press the wheel button a second time then the file
will open, even if there is a large time interval between the two clicks. On
one computer I upgraded from Office 2000 while the other was a fresh instal
on a fresh XP installation. Is there a fix for this problem?
Thanks
--
Joe
in excel, it seems there is some sort of lock on so when i move my mouse
around in a worksheet, it highlights all of the cells i move across. this
happens when the left mouse button isn't being touched, and i can't work out
what i have done to do this. have already tried the f8 button, but this
doesn't help
Hello,
I`m new VBA user. My problem is this: I need sheet, what increment active cell value when I doubleclick it. Is it possible with VBA?
I have a ComboBox with a list of 16 different flange types. The target Cell is $N5. I want the info in the target cell to appear in a highlighted cell in column F if I double click on one of the flange types in the combo box. What do you suggest?
Hello Again.
I recently posted for a on click sort question. With your guys help I got it working just fine. I thought if I could see how you did it I could adapt it to do more. I was not able to adapt it to my needs.
The problem I am encountering is that with my knowledge I can only get one range to work on the worksheet_before doubleclick function and thats the sort range.
I need several different ranges with each range giving a target value uinique to that range.
Attached is a example sheet. If it is not clear enough let me know.
Thank you in advance.
Hi Everyone
I had some help a few days ago and got given some help with a hyperlink that did not figure out quite how I wanted it. I needed to work in a way that on my work sheet I would have listed in column B
part numbers e.g 10062, I wanted it so the actual number could be double clicked and that would open acrobat 5.0 and then open a pdf file stored in this directry saved under the actual part number clicked on
Quote:
ChDir "P:\Design\PDF Standard Part Drawings"
The only problem is that I need the entire column from cell b10 onward to be formatted in this way so ny part numbers added can be used in the way above?
Can anyone please help
Many thanks
Denzil
How to make Application.DoubleClick work for worsheet cells ?
It works for embeeded objects as well as for chart sheets but doesn't seem to carry the doubleclick action on cells as expected.
Any ideas ?
Regards.
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If ActiveCell = ("d19") Then
UserForm8.Show
End Sub
If the activecell is D19 userform.show, not working? any thoughts why..thanks
I am using a worksheet that contains a column (e.g. Col. C) of dates (format is dd/mm). A second worksheet has one cell (Col. K, Row 3)that needs to be populated by the data from any one of the cells in Col C when I doubleclick on that specific cell. I would like to be able to jump to worksheet2!K3 when I doubleclick at the same time. How do I go about this. There are 875 rows in Col. C.
Tnx
Bob
Hello everyone,
does anybody know what does exactly DoubleClick on a cell do
and how to apply this action on a selection of cells?
I have a column formated as GENERAL. At the same time I need to make part of that column TEXT. I use single quote (') in front of value to let Excel know that it is TEXT type. I use formula to put single quotes (') into required cells.
However, Excel doesn't accept the single quote (') as a control symbol untill I double-click on the cell.
I need to repeat this double-click for each cell.
Is there any way to apply this action (double-click ) on a selection of cells?
Thank you.
surotkin