Enter day, default month and year

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I would like a user to enter just the day in a cell and then display a fixed
month and year.
For example:
user enters 25
Date display will be January 25, 2008
I have a separate worksheet for each month, so 12 worksheets that will
default to corresponding month. They will all be the year 2008.
Thanks for any tips.
 
Let's say the entries are in column A. In the worksheet event code area put
the following:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim v As Integer
Set r = Range("A:A")
If Intersect(Target, r) Is Nothing Then Exit Sub
v = Target.Value
Application.EnableEvents = False
Target.Value = DateSerial(2008, 1, v)
Target.NumberFormat = "mmmm dd, yyyy"
Application.EnableEvents = True
End Sub

This is good for the January worksheet. For the February worksheet simply
replace:
Target.Value = DateSerial(2008, 1, v)
with
Target.Value = DateSerial(2008, 2, v)

REMEMBER: the worksheet code area, not a standard module.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top