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.

Emp IDLast NameFirst NameDepartmentDivisionSalaryStart DateBirth DateAgeYears In ServiceNew Salary 1New Salary 2Birth Month
1011GortonHazelAccountingCopier$27,597.85 2/3/200011/21/19645318
1012PrestonLizaEngineeringPrinter$43,394.15 1/26/200612/2/19843312
1041TercanRobertR and DPrinter$28,043.68 4/16/20029/21/19655216
1054SmithHowardArtCopier$25,176.06 4/16/20098/9/1987309
1055AlbertMaxineMarketingCopier$26,040.56 4/8/19998/20/19675019
1075KaneSherylArtPrinter$23,239.44 8/7/20068/28/19793811
1152HendersMarkAccountingPrinter$26,646.20 1/21/200010/23/19714618
1153PlantAllenAccountingPrinter$28,043.68 1/13/200911/3/1963549
1167BerwickSamMarketingCopier$31,913.88 4/18/20019/28/19704717
1168AsonteToniEngineeringFax$63,035.88 4/10/19997/8/19704719

<colgroup><col><col><col><col><col><col><col><col><col span="2"><col><col><col></colgroup><tbody>
</tbody>
 
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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,215,424
Messages
6,124,817
Members
449,190
Latest member
rscraig11

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