A resource for users and developers of Microsoft Excel |
|||||||||
| Email us your FAQ suggestion. |
|||||||||
Visit often ! Pages are updated daily. |
|||||||||
This is the Excel "How to" Frequently Asked Questions page |
|||||||||
Answers to Frequently Asked Questions about how to do common tasks in Microsoft Excel. |
|||||||||
Excel "How to" FAQs |
| How to automatically insert the colon character : when entering a time? |
| Example |
In this example, you want to enter the time of day in column A without needing to enter the colon character : yourself. That is, you want to enter the time of 12:30 PM by entering the four digits 1230 and have the cell display 12:30 PM while regarding the entry as a bona fide time, not just as a custom-formatted four-digit number. It is possible to avoid the colon entry by entering times as their decimalized number, but that means 12:30 PM gets entered as .520833333333333 which is not an option to do or to memorize all 1440 decimalized numbers of the 24-hour day.
|
| VBA |
To enter times in column A by keying in four digits without the colon, do this: Right click on the worksheet tab, left click on View Code, and paste the following code into the large white area that is the worksheet module. Press Alt+Q to return to the worksheet. Private Sub Worksheet_Change(ByVal Target As Range) Select Case Len(sTxt) Be aware of 2 items: (1) (2)
|