ALLAROUNDOFFICE
Board Regular
- Joined
- Apr 26, 2014
- Messages
- 61
How can I hard code a column of cells to convert the user entered data of "042614" or "42614" into a specific date format such as 04/26/2014?
It does not do that for me... I get 4/26/2014 no matter what cell in Column A that I enter it in.Thanks - I will try this because the program by Rick is only working in the first cell and then converts wrong. It is turning 042614 into 09/01/16!
this is only working in the first cell in column a. The next cell down in converting 42614 into 9/1/2016 - any help would be appreciated!you can do this conversion automatically using the following event code. Assuming your column is column a...
Rich (BB code):private sub worksheet_change(byval target as range) dim cell as range on error goto nothingincolumn if not intersect(target, columns("a")) is nothing then for each cell in intersect(target, intersect(columns("a"), activesheet.usedrange)) if not isdate(cell.value) and not cell.value like "*[!0-9]*" then cell.value = format(cell.value, "0/00/00") end if next end if nothingincolumn: End sub
how to install event code
------------------------------------
if you are new to event code procedures, they are easy to install. To install it, right-click the name tab at the bottom of the worksheet that is to have the functionality to be provided by the event code and select "view code" from the popup menu that appears. This will open up the code window for that worksheet. Copy/paste the event code into that code window. That's it... The code will now operate automatically when its particular event procedure is raised by an action you take on the worksheet itself. Note... If you are using xl2007 or above, make sure you save your file as an "excel macro-enabled workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "ok" (depending on the button label for your version of excel) the next time you open your workbook.
4/26/2014 |
9/1/2016 |
Do I need to format that column in a certain way before enabling the event code procedure possibly?
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Cell As Range
On Error GoTo NothingInColumn
If Not Intersect(Target, Columns("A")) Is Nothing Then
For Each Cell In Intersect(Target, Intersect(Columns("A"), ActiveSheet.UsedRange))
If Not IsDate(Cell.Value) And Not Cell.Value Like "*[!0-9]*" Then
[COLOR=#FF0000][B]Cell.NumberFormat = "General"[/B][/COLOR]
Cell.Value = Format(Cell.Value, "0/00/00")
End If
Next
End If
NothingInColumn:
End Sub