MonthName Function

Bmaho

New Member
Joined
Sep 6, 2017
Messages
13
Can anyone help me write a macro for a school project I am working on? I think I need to use a MonthName function, I'm not sure how though. The question is:

Write a Macro, that will put the employee’s month of birth in column “Birth Month”, for each employee in the database. Month should be in text, e.g., March, May etc. Must write VBA code from scratch.

The following is a sample of the worksheet, The Range for the following on my worksheet is A8:M61 and the "Birth Month" column where the name of the month goes is M8.

[TABLE="width: 937"]
<colgroup><col><col><col><col><col><col><col><col><col span="2"><col><col><col></colgroup><tbody>[TR]
[TD]Emp ID[/TD]
[TD]Last Name[/TD]
[TD]First Name[/TD]
[TD]Department[/TD]
[TD]Division[/TD]
[TD]Salary[/TD]
[TD]Start Date[/TD]
[TD]Birth Date[/TD]
[TD]Age[/TD]
[TD]Years In Service[/TD]
[TD]New Salary 1[/TD]
[TD]New Salary 2[/TD]
[TD]Birth Month[/TD]
[/TR]
[TR]
[TD]1011[/TD]
[TD]Gorton[/TD]
[TD]Hazel[/TD]
[TD]Accounting[/TD]
[TD]Copier[/TD]
[TD="align: right"]$27,597.85 [/TD]
[TD="align: right"]2/3/2000[/TD]
[TD="align: right"]11/21/1964[/TD]
[TD]53[/TD]
[TD]18[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1012[/TD]
[TD]Preston[/TD]
[TD]Liza[/TD]
[TD]Engineering[/TD]
[TD]Printer[/TD]
[TD="align: right"]$43,394.15 [/TD]
[TD="align: right"]1/26/2006[/TD]
[TD="align: right"]12/2/1984[/TD]
[TD]33[/TD]
[TD]12[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1041[/TD]
[TD]Tercan[/TD]
[TD]Robert[/TD]
[TD]R and D[/TD]
[TD]Printer[/TD]
[TD="align: right"]$28,043.68 [/TD]
[TD="align: right"]4/16/2002[/TD]
[TD="align: right"]9/21/1965[/TD]
[TD]52[/TD]
[TD]16[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1054[/TD]
[TD]Smith[/TD]
[TD]Howard[/TD]
[TD]Art[/TD]
[TD]Copier[/TD]
[TD="align: right"]$25,176.06 [/TD]
[TD="align: right"]4/16/2009[/TD]
[TD="align: right"]8/9/1987[/TD]
[TD]30[/TD]
[TD]9[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1055[/TD]
[TD]Albert[/TD]
[TD]Maxine[/TD]
[TD]Marketing[/TD]
[TD]Copier[/TD]
[TD="align: right"]$26,040.56 [/TD]
[TD="align: right"]4/8/1999[/TD]
[TD="align: right"]8/20/1967[/TD]
[TD]50[/TD]
[TD]19[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1075[/TD]
[TD]Kane[/TD]
[TD]Sheryl[/TD]
[TD]Art[/TD]
[TD]Printer[/TD]
[TD="align: right"]$23,239.44 [/TD]
[TD="align: right"]8/7/2006[/TD]
[TD="align: right"]8/28/1979[/TD]
[TD]38[/TD]
[TD]11[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1152[/TD]
[TD]Henders[/TD]
[TD]Mark[/TD]
[TD]Accounting[/TD]
[TD]Printer[/TD]
[TD="align: right"]$26,646.20 [/TD]
[TD="align: right"]1/21/2000[/TD]
[TD="align: right"]10/23/1971[/TD]
[TD]46[/TD]
[TD]18[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1153[/TD]
[TD]Plant[/TD]
[TD]Allen[/TD]
[TD]Accounting[/TD]
[TD]Printer[/TD]
[TD="align: right"]$28,043.68 [/TD]
[TD="align: right"]1/13/2009[/TD]
[TD="align: right"]11/3/1963[/TD]
[TD]54[/TD]
[TD]9[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1167[/TD]
[TD]Berwick[/TD]
[TD]Sam[/TD]
[TD]Marketing[/TD]
[TD]Copier[/TD]
[TD="align: right"]$31,913.88 [/TD]
[TD="align: right"]4/18/2001[/TD]
[TD="align: right"]9/28/1970[/TD]
[TD]47[/TD]
[TD]17[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1168[/TD]
[TD]Asonte[/TD]
[TD]Toni[/TD]
[TD]Engineering[/TD]
[TD]Fax[/TD]
[TD="align: right"]$63,035.88 [/TD]
[TD="align: right"]4/10/1999[/TD]
[TD="align: right"]7/8/1970[/TD]
[TD]47[/TD]
[TD]19[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
I may be mistaken, but would Format only reformat the dates in "Date of birth" (column H) to display the month name?
No, this is not cell formatting (which is a worksheet functionality), rather, Format is a VBA function and, like all functions, it returns a value that can be used in anyway you see fit. Format is a powerful function (it can take numbers, dates and text and manipulate them is quite a few different ways) which, one day, you should spend time learning, but now is apparently not the time as your professor has you on the MonthName function for now.



What I am trying to do is use the dates in column "H" to display the "birth month" in column "M". Prior to trying to add Format to the code.
You are getting a full date from Column H, but you need to output to a different column the name of the month for that date. The first argument for the MonthName function is a number... the number of the month for the cell containing the date in Column H that your loop is currently iterating. What function did you learn that will return the month number from a date? Use that function call as the first argument for the MonthName function and then assign that MonthName expression to the active cell inside your loop.
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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