Need Help Writing a Macro

sliollio

New Member
Joined
Sep 8, 2014
Messages
22
Hi all! I am fairly new to the VBA portion of excel and could use some help with writing a macro!
Any help is greatly appreciated.

I am trying to write a macro that will:
  • prompt the user for a date (any date) in mm/dd/yyyy format
  • display the year, month, and day in separate MsgBox(es)
  • display a notification as to whether or not the date entered is a past, present, or future date and if it is a past/present date then compute the difference (given in years, months, days) between the entered date and the current date

Here is what I have so far which I know is no where near close, but like I said, I am very new to this, thus very confused

Sub macro1()
Dim TheDate As Variant
Dim Day As Integer
Dim Month As Integer
Dim Year As Integer
TheDate = InputBox("Insert: Date (mm/dd/yyyy)")
MsgBox (Month)
MsgBox (Day)
MsgBox (Year)

EndSub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Okay, as a starter, have a look at changing this MsgBox lines to something like
Code:
MsgBox (Month)

To

MsgBox format(Thedate,"mmm")

I guess you can work out the bvious difference between months, years and days
Also remember, the more letters you use the better the dexcription of the item
"mm" will give you a number
"mmm" will give you short text
"mmmm" will give you full text
 
Upvote 0
Ok awesome! That works well. Now I've got it to where it displays exactly what the user inputs. But can't figure out how to get it to read and display the 3 separately. Sorry for all the questions! I kind of suck at this :eek:
 
Upvote 0
Here's where Im at now. It is running my first two steps fine. Just have no clue where or how to begin the third.

Sub macro1()
Dim TheDate As Variant
TheDate = InputBox("Insert: Date (mm/dd/yyyy)")
MsgBox Format(TheDate, "mmmm")
MsgBox Format(TheDate, "dd")
MsgBox Format(TheDate, "yyyy")

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,873
Members
449,056
Latest member
ruhulaminappu

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