- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Auto Add/Enter Current Date/Time in a Cell with Double Clicking in Excel?
When we want to add the current date or time in Excel multiple times, it can be a time-consuming process, so we can make it very simple by adding a short cut to finish the process. Read this tutorial to learn how you can use doubleclicking in Excel to automatically add or enter the current date or time in a cell.
Auto Add/Enter Current Date in a Cell with DoubleClicking in Excel
We'll add some VBA code to the sheet here, and the date will be displayed every time we double-click in a cell. Let us see a simple process to understand how we can automatically add the current date to a cell by double clicking in Excel.
Step 1
Consider creating a new Excel sheet and right-clicking on the sheet name to open the VBA application, then entering the programme into the text box as shown in the image below.
Program
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) 'Updated By Nirmal If Not Intersect(Target, Range("A1:B10")) Is Nothing Then Cancel = True Target.Formula = Date End If End Sub
In the code, the range A1:B10 represents the range where our code will work.
Step 2
Now save the sheet as a macro-enabled worksheet, close the VBA application using the command "Alt + Q", and every time we double-click on the cells, we can see that the current date is displayed on the sheet, as shown in the below image.
Auto Add/Enter Current Time in a Cell with DoubleClicking in Excel
In this section, we will insert VBA code into the sheet, and then when we double-click in a cell, the date and time will be displayed. Let's look at a simple example to see how we can double-click to add the current time to a cell in Excel.
Step 1
Consider creating a new Excel sheet and right-clicking on the sheet name to open the VBA application, then enter the program into the text box as shown in the image below.
Program
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) If Not Intersect(Target, Range("A1:C20")) Is Nothing Then Cancel = True Target.Formula = Now() End If End Sub
Step 2
Now save the sheet as a macro-enabled worksheet, close the VBA application using the command "Alt + Q", and every time we double-click on the cells, we can see that the current time is displayed on the sheet as shown in the below image.
Conclusion
In this tutorial, we used a simple example to show how we can add the current date and time to a cell in Excel by double-clicking to highlight a specific set of data.
To Continue Learning Please Login
Login with Google