Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel number of month 1

Status
Not open for further replies.

swtrader

IS-IT--Management
Dec 23, 2004
182
US
I need to return the 'month-number' in a cell. -- i.e., 7 for July (not 07, which is what I get on anything that I try).

Suggestions?

Thanks.

swtrader
-- If you don't know where you're going, you'll always know when you're not there.
 
It's just a number format issue, isn't it ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 



Hi,

How about
Code:
dim iMonth as integer, sMonth as string
iMonth = Month(YourDate)
sMonth = Format(Yourdate, "m")
If you want the Month NUMBER, do not use the FORMAT function which returns a STRING (which, of course, you could COERCE to a numeric value)


Skip,

[glasses] [red][/red]
[tongue]
 
I messed up the request. It's the year that I need in single digit form. I've tried "y" but I still get 07. A department has made the single digit a portion of a tracking number. (I don't question -- I just try to serve.)

Thanks.

Oh, please be detailed as to where and how I use the formatting. I'm a VBA newbie.

swtrader
-- If you don't know where you're going, you'll always know when you're not there.
 




"It's the year that I need in single digit form"


WHAT? The YEAR is 2007

What you want is the last two digits of the year in one digit format.
Code:
iYear = Cint(Format(TheDate, "yy"))


Skip,

[glasses] [red][/red]
[tongue]
 
Right(Year(theDate), 1)
or
Year(theDate) Mod 10

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV -- Right worked (I had tried that but didn't include "Year") Thanks.

Skip -- I put =Cint(Format(AE3,"yy")) in cell AE4 and got #NAME? . for future ref, what did I do wrong? Thanks.

swtrader
-- If you don't know where you're going, you'll always know when you're not there.
 



This is a VBA forum. I gave you VBA code, not SHEET code.

Skip,

[glasses] [red][/red]
[tongue]
 





Right(Year(theDate), 1) will not give you the results you want for years greater than 2009 or less than 2000.

Skip,

[glasses] [red][/red]
[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top