Handy VBA To Calculate Person Age
This handy VBA procedure is just to show you how we can calculate and display someone Age. To do this, of course we need to know their date of birth first, then simply using datediff and mod vba functions we can calculate how old is he/she.
Sub PersonAge()
Dim iYears As Integer, iMonths As Integer, iMonth As Integer
Dim dtDateofbirth As Date
dtDateofbirth = _
CDate(InputBox("Input your date of birth (yyyy-mm-dd)", "Date of birth"))
iYears = DateDiff("yyyy", CDate(dtDateofbirth), Date)
iMonths = (DateDiff("m", CDate(dtDateofbirth), Date)) Mod (iYears * 12)
MsgBox "Your age are " & iYears & " year(s) and " & iMonths & " month(s)"
End Sub
For this example, I use MsgBox and InputBox to get input and display the output data, but we can change it to worksheet cells reference if we want to integrate this calculation in our Excel Worksheet.
Related Entries
VBA Delete Excel Rows Based on Certain Date
Let say I have a bunch of formatted data in my Excel sheet, and in Column A I have a dates. Then I wanna filter all the data base on certain date, for example 1 Jan 2009, and delete all others data before that date. The algorithm is like this: I’ll create a loop from the...
Getting Cell Reference With Input Box
We can get an input from user using Input Box, but we also can use the Input Box to get the address of cell reference in Microsoft Excel. Using simple Excel VBA procedure below we can ask user to select range of cells (as copy input) and where they want it paste.Sub CopyPaste()Dim InputCells As Excel.Range Dim...
Excel Extract Cell Comments
Excel VBA/Macro example below will extract comment from every cells with comment, and put the summary in the cell selected by user using Excel input box (read more about how to get cell reference using input box here). Sub CreateCommentsSummary()Dim rgComments As Range, rgCell As Range, rgOutput As Range, iRow As Integer,...
How to create Excel function/formula?
This is the reason why the power of Excel when combined with VBA is almost limitless. When we can’t found any Excel function that suite our need, we can built it easily using Excel VBA. If Excel macro or SUB procedure is easily created using Record Macro button, and usually build to simplify a complex process...
Create New Excel Worksheet With VBA
The Excel VBA macro below will create a new Excel Worksheet called ‘RawData’ or we can use msgbox to ask for the Worksheet name if needed. If there is already a Worksheet called RawData, user will be ask whether they want to use the old Worksheet and cancel new Worksheet creation, or delete the old Worksheet...
Valuable Resources
- Microsoft Excel 2003/2007 Video Tutorials
Step-by-step video guide to mastering Charts, PivotTable, Data Analysis and Macro programming in Microsoft Excel in 5 hours.
- 101 Secrets of Microsoft Excel
Discover 101 of Excels little-known secrets that have been hiding right under your nose.
- Top Tips & Tricks to Get You Started in Microsoft Excel 2007
This is an ebook by Carol Bratt's, a Microsoft Certified Professional who has plenty of experience explaining things in simple English.
- Microsoft Office 2003/XP/2007 Training Videos
Discover an easy to use, hands-on interactive course that will teach you how to unleash the true power of Microsoft Office 2003/XP/2007.
If you found this page useful, please consider bookmark it using social media or add a link to this page.
Incoming search engine terms: age calculation in excel, calculate age in vba excel, how to calculate in Excel VBA, vba i want to calculate and report age ranges