I want to enter only the month and the year in a cell: for example,
i'll key in 08/01 (August 2001) and i want to format the cell to
display Aug-01. Is there a way to do this?
Thanks,
Jayme
If you could use different columns for data entry vs display, you could use the
formula:
=DATE(1900+100*(MOD(A1,100)<30)+MOD(A1,100),INT(A1/100),1)
to convert your entry.
Otherwise, you would need a VBA event driven macro. Something like the
following might work for you. To enter it, right click on the worksheet tab
and select View code from the menu that opens. Then paste the below macro into
the window that opens.
============================
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim AOI As Range
Dim temp As Variant, yr As Integer, mnth As Integer
Const DtFormat As String = "mm-yy"
Application.EnableEvents = False
Set AOI = [A:A]
If Intersect(Target, AOI) Is Nothing Then GoTo DONE
If Target.Count <> 1 Then GoTo DONE
temp = InputBox("Enter Date String", , Format(Target.Value, "mmyy"))
If Len(temp) = 0 Then
Target.Clear
GoTo DONE
End If
yr = temp Mod 100
mnth = Int(temp / 100)
Target.Value = DateSerial(yr, mnth, 1)
Target.NumberFormat = DtFormat
DONE: Application.EnableEvents = True
End Sub
=======================
--ron