Adding the year to the month

Godders199

Active Member
Joined
Mar 2, 2017
Messages
313
Office Version
  1. 2013
Hello,, i use the following code to pull the month from the date, i now need to pull the year also , for example September 18. can this be done within this code, or do i need to start again?

If IsDate(db.Cells(w, 4).Value) Then
db.Cells(w, 16).Value = MonthName(Month(db.Cells(w, 4).Value), False)

End If

thanks
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try this instead:
Code:
[COLOR=#333333]If IsDate(db.Cells(w, 4).Value) Then[/COLOR]
[COLOR=#333333]    db.Cells(w, 16).Value = Format(db.Cells(w, 4).Value), "mmmm yy")[/COLOR]
[COLOR=#333333]End If[/COLOR]
 
Upvote 0
Thanks, have given it ago, does not like the coma after value, if I remove or change it does not like “mmmm yy”. Also tried changing format to text
 
Upvote 0
Whoops, minor typo. Actually we just need to remove the ")" after the word "Value", i.e.
Code:
[COLOR=#333333]If IsDate(db.Cells(w, 4).Value) Then[/COLOR]
[COLOR=#333333]    db.Cells(w, 16).Value = Format(db.Cells(w, 4).Value, "mmmm yy")[/COLOR]
[COLOR=#333333]End If[/COLOR]
 
Upvote 0
thanks it now highlights "format" with the fullowing error - Wrong number of arguments or invalid propert assignment"
 
Upvote 0
thanks for your help, i have got this to work, doing the following
If IsDate(db.Cells(w, 4).Value) Then
db.Cells(w, 16).Value = MonthName(Month(db.Cells(w, 4).Value)) & " " & Year(db.Cells(w, 4).Value)
 
Upvote 0
thanks it now highlights "format" with the fullowing error - Wrong number of arguments or invalid propert assignment"
Sounds like you may have made a typo in copying the formula. FORMAT is a valid VBA function (see: https://www.techonthenet.com/excel/formulas/format_string.php), and I did test it out.
You are using Excel, and not Google Sheets, right?

If you want the result to be Text so it is not converted to another date format, just make one small modification:
Code:
If IsDate(Db.Cells(w, 4).Value) Then
    Db.Cells(w, 16).NumberFormat = "@"
    Db.Cells(w, 16) = Format(Db.Cells(w, 4).Value, "mmmm yy")
End If
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top