FARMAT DATE

srizki

Well-known Member
Joined
Jan 14, 2003
Messages
1,791
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I would like to format a cell in a way so that I only have to put number of a month, from 1 - 12 and it should convert it to month and year. For example if I put 9 it should convert it to September 2006.

I am using this '=DATE(2006,B3,30) formula, but I have to use another cell to put number of the month.

Thanks
 

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,955
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
It can't be done with cell formatting, but it can be done with VBA. How do you want to determine what year it should be? Always the current year or what? And in what range do you want this to happen?
 

srizki

Well-known Member
Joined
Jan 14, 2003
Messages
1,791
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I want 2006, but can I change it as I want, year and range, on the code.
I will appreciate it.

thanks
 

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,955
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
The code could figure out what the current year was, but since you want it hardcoded, here you go, this is currently set for Column A.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim yr As Integer, r As Range, c As Range
yr = 2006
Set r = Intersect(Target, Range("A:A"))
If r Is Nothing Then Exit Sub
Application.EnableEvents = False
    For Each c In r
        If IsNumeric(c) Or IsDate(c) Then
            c = Int(c)
            c = DateSerial(yr, c, 1)
            c.NumberFormat = "mmmm yyyy"
        End If
    Next
Application.EnableEvents = True
End Sub
 

srizki

Well-known Member
Joined
Jan 14, 2003
Messages
1,791
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Thanks Hotpepper.
sorry it is late.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,544
Messages
5,529,457
Members
409,879
Latest member
Aussie_Excel_Wanna_Be
Top