Rows for years and age based on date of birth

Antoinelhm

New Member
Joined
Nov 12, 2018
Messages
5
Hello all,

First time poster,

I have a list of people that have different date of birth. I made a " template " page and a vba module to automaticly create a sheet based on the template for each person in the list. Now in the template page i need to figure out how to create 2 dynamic colomns based on the date of birth of the person that tracks years and age.

So let's say someone is born in 1990 then i need
Dob : 1990/01/01

row 1 col a 1991 col b 1 years old
r2 col a 1992 col b 2 years old
r 29 col a 2018 col b 28 years.
I have to also have a way to make it future proof so that it stops at the current year +1 so that the last row as of 2018 is 2019 and in 2019 it's 2020 etc...


I can do an index match to get the date of birth from the " master " sheet but after that i need the range to vary based on the age of the person and the years. On the template page is not a problem if i get n/a but i need to have the rows created based on the info

I hope i was clear enough.

Thanks in advance for all the help !

-A
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hello all,

First time poster,

I have a list of people that have different date of birth. I made a " template " page and a vba module to automaticly create a sheet based on the template for each person in the list. Now in the template page i need to figure out how to create 2 dynamic colomns based on the date of birth of the person that tracks years and age.

-A

Can you post your data sample in a table?
To copy a simple table from worksheet:
1. In your worksheet select the table/range then copy.
2. Back to the thread, in the reply box, scroll down and press Go Advanced
3. Paste the table
4. Click inside the table then click icon 'Table Properties'
5. Set table style to Full Grid
6. OK

A simple table would look like this:

NAMEID
MaysonA01
AmayaA03
CaydenA04

<tbody>
</tbody>
 
Upvote 0
Hello,

Here is a idea of what it would look like

SHEET "MASTER"

Name1st KidDate of birth
Tawna ZupanMira2014-06-01
Larissa KromerBerniece2005-01-21
Luella SchaferTad2001-11-30
Felecia CorsonCarolina2003-02-04
Dolores MajorDewey1995-11-14
Gonzalo DimasSunday1994-02-02
Filomena ProsperMan1992-08-25
Ricardo HasslerVallie1999-06-28
Gloria LanhamOrville2017-03-11
Maximo DuarteLeanora1992-07-02

<tbody>
</tbody>

That is my sample of the first page "master"

and here is a copy of the filled "template"

SHEET " TEMPLATE"
Subscriber:Luella SchaferDate of Birth:1995-11-30
Beneficiary :Tad
YearDepositsGrantWithdrawal
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
Totals

<tbody>
</tbody>

Now i did the years manually but i want it to be done automatically based on the date of birth.
I'm already populating with index match the name of the kid and and date of birth and im getting the subscriber info based on the sheet name !

Thanks !

-A
 
Upvote 0
Hello,

Here is a idea of what it would look like
Now i did the years manually but i want it to be done automatically based on the date of birth.
I'm already populating with index match the name of the kid and and date of birth and im getting the subscriber info based on the sheet name !

Thanks !

-A


1. By 2 dynamic colomns you mean column Year & Deposits?
I made a " template " page and a vba module to automaticly create a sheet based on the template for each person in the list. I have a list of people that have different date of birth. I made a " template " page and a vba module to automaticly create a sheet based on the template for each person in the list. Now in the template page i need to figure out how to create 2 dynamic colomns based on the date of birth of the person that tracks years and age.



2. Do you want the macro to put 1 year, 2 year etc in column B (Deposits)?
So let's say someone is born in 1990 then i need
Dob : 1990/01/01
row 1 col a 1991 col b 1 years old
r2 col a 1992 col b 2 years old
r 29 col a 2018 col b 28 years.
I have to also have a way to make it future proof so that it stops at the current year +1 so that the last row as of 2018 is 2019 and in 2019 it's 2020 etc...


3. The template example above, can you show what the template look like before (before you change anything or add any data) & after (the result you expected)?

4. Can you show us the code?
I made a " template " page and a vba module to automaticly create a sheet based on the template for each person in the list.


5. Can you upload your sample workbook (without classified data) somewhere (maybe to dropbox.com or google drive) then post the link here?
 
Upvote 0
Here is a link to the file i've removed the sensitive data & the name and birthdays are fictitious :

https://drive.google.com/file/d/1wZWJEsZXkkbT1B2s2OSXDjJ7wLkKoUKz/view?usp=sharing

Q #1 & 2 > Sorry Akuini i forgot to insert a column " Age "

so it would be like this empty

YearAgeDepositsGrantWithdrawal

<tbody>
</tbody>

And filled

YearAgeDepositsGrantWithdrawal
19901$2500$ 250
19912$2500$ 250
...
201828$ 3500

<tbody>
</tbody>

Now for the second part of the data I'm still not sure how i am going to get those.

For Q4 you can check in the VBA modules it's called " Sheetfromtemplate"

Thanks for looking into this !
 
Upvote 0
Here is a link to the file i've removed the sensitive data & the name and birthdays are fictitious :

https://drive.google.com/file/d/1wZWJEsZXkkbT1B2s2OSXDjJ7wLkKoUKz/view?usp=sharing

Q #1 & 2 > Sorry Akuini i forgot to insert a column " Age "

Q3 so it would be like this empty

YearAgeDepositsGrantWithdrawal

<tbody>
</tbody>

And filled

YearAgeDepositsGrantWithdrawal
19901$2500$ 250
19912$2500$ 250
...
201828$ 3500

<tbody>
</tbody>

Now for the second part of the data where i insert the deposit, grants and withdrawals im gonna be inserting them from the data page. I put a few example also in the file

For Q4 you can check in the VBA modules it's called " Sheetfromtemplate"

Thanks for looking into this !
 
Upvote 0
Here is a link to the file i've removed the sensitive data & the name and birthdays are fictitious :


Thanks for looking into this !

Ok, I write a sub name "addYear".
I put this line below in your sub "SheetsFromTemplate" to call the sub.

Code:
        NmSTR = FixStringForSheetName(CStr(Nm.Text))            'use UDF to create a legal sheetname
        [COLOR=#0000cd]Call addYear(Nm)  [/COLOR]                                      '>>> calling sub addYear
        If Not Evaluate("ISREF('" & NmSTR & "'!A1)") Then       'if sheet does not exist...
            wsTEMP.Copy After:=.Sheets(.Sheets.Count)           '...create it from template
            ActiveSheet.Name = NmSTR                            '...rename it
        End If

so you just hit the button 'Check for new client'.

Notes:
1. I didn't insert anything in column Deposits, Grant, & Withdrawal, because I don't know where the data is & I think you will do that part by yourself.
2. The part to add hyperlink is messed up so I disable it. We deal with this later.
3. In Template: col Year format should be General
4. In Template: why col Child #3 is col S, it's off 1 column, it should be col R.
5. In Master: why every name in col A has a trailing space?

Code:
[B][COLOR=Royalblue]Sub[/COLOR][/B] addYear(rng [B][COLOR=Royalblue]As[/COLOR][/B] Range)
[I][COLOR=seagreen]'https://www.mrexcel.com/forum/excel-questions/1077355-rows-years-age-based-date-birth.html[/COLOR][/I]
[B][COLOR=Royalblue]Dim[/COLOR][/B] wsM [B][COLOR=Royalblue]As[/COLOR][/B] Worksheet, wsT [B][COLOR=Royalblue]As[/COLOR][/B] Worksheet
[B][COLOR=Royalblue]Dim[/COLOR][/B] ce [B][COLOR=Royalblue]As[/COLOR][/B] [B][COLOR=Royalblue]Long[/COLOR][/B], rc [B][COLOR=Royalblue]As[/COLOR][/B] [B][COLOR=Royalblue]Long[/COLOR][/B], n [B][COLOR=Royalblue]As[/COLOR][/B] [B][COLOR=Royalblue]Long[/COLOR][/B], j [B][COLOR=Royalblue]As[/COLOR][/B] [B][COLOR=Royalblue]Long[/COLOR][/B], x [B][COLOR=Royalblue]As[/COLOR][/B] [B][COLOR=Royalblue]Long[/COLOR][/B]
[B][COLOR=Royalblue]Dim[/COLOR][/B] dy [B][COLOR=Royalblue]As[/COLOR][/B] [B][COLOR=Royalblue]Variant[/COLOR][/B], vx [B][COLOR=Royalblue]As[/COLOR][/B] [B][COLOR=Royalblue]Variant[/COLOR][/B], va [B][COLOR=Royalblue]As[/COLOR][/B] [B][COLOR=Royalblue]Variant[/COLOR][/B]

[B][COLOR=Royalblue]Set[/COLOR][/B] wsM = Sheets([COLOR=brown]"Master"[/COLOR])
[B][COLOR=Royalblue]Set[/COLOR][/B] wsT = Sheets([COLOR=brown]"Template"[/COLOR])

rc = rng.Row
wsT.Range([COLOR=brown]"B10:AM200"[/COLOR]).ClearContents

    [B][COLOR=Royalblue]With[/COLOR][/B] wsM
        ce = .Rows(rc).Find([COLOR=brown]"*"[/COLOR], SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
        vx = .Range(.Cells(rc, [COLOR=brown]"E"[/COLOR]), .Cells(rc, ce))
    [B][COLOR=Royalblue]End[/COLOR][/B] [B][COLOR=Royalblue]With[/COLOR][/B]
 
 n = [COLOR=crimson]2[/COLOR]
[B][COLOR=Royalblue]For[/COLOR][/B] j = [COLOR=crimson]2[/COLOR] [B][COLOR=Royalblue]To[/COLOR][/B] UBound(vx, [COLOR=crimson]2[/COLOR]) [B][COLOR=Royalblue]Step[/COLOR][/B] [COLOR=crimson]2[/COLOR]

    dy = [B][COLOR=Royalblue]CStr[/COLOR][/B](Year([B][COLOR=Royalblue]CDate[/COLOR][/B](vx([COLOR=crimson]1[/COLOR], j))))
    x = [B][COLOR=Royalblue]CStr[/COLOR][/B](Year([B][COLOR=Royalblue]Date[/COLOR][/B]) + [COLOR=crimson]2[/COLOR] - dy)
    [B][COLOR=Royalblue]ReDim[/COLOR][/B] va([COLOR=crimson]1[/COLOR] [B][COLOR=Royalblue]To[/COLOR][/B] x, [COLOR=crimson]1[/COLOR] [B][COLOR=Royalblue]To[/COLOR][/B] [COLOR=crimson]2[/COLOR])
        [B][COLOR=Royalblue]With[/COLOR][/B] wsT
            [B][COLOR=Royalblue]For[/COLOR][/B] i = [COLOR=crimson]1[/COLOR] [B][COLOR=Royalblue]To[/COLOR][/B] UBound(va, [COLOR=crimson]1[/COLOR])
                va(i, [COLOR=crimson]1[/COLOR]) = dy
                va(i, [COLOR=crimson]2[/COLOR]) = i
                dy = dy + [COLOR=crimson]1[/COLOR]
            [B][COLOR=Royalblue]Next[/COLOR][/B]
            .Cells([COLOR=crimson]10[/COLOR], n).Resize(UBound(va, [COLOR=crimson]1[/COLOR]), [COLOR=crimson]2[/COLOR]) = va
        [B][COLOR=Royalblue]End[/COLOR][/B] [B][COLOR=Royalblue]With[/COLOR][/B]
        n = n + [COLOR=crimson]8[/COLOR]
        [B][COLOR=Royalblue]If[/COLOR][/B] n = [COLOR=crimson]18[/COLOR] [B][COLOR=Royalblue]Then[/COLOR][/B] n = n + [COLOR=crimson]1[/COLOR]
    
[B][COLOR=Royalblue]Next[/COLOR][/B]

[B][COLOR=Royalblue]End[/COLOR][/B] [B][COLOR=Royalblue]Sub[/COLOR][/B]


The workbook:

https://www.dropbox.com/s/fi65l7u09lbx6pb/a1077355a - MRexcel copy - WIP-01.xlsm?dl=0
 
Upvote 0
Hey Akuini,

Thanks for that! it works would you mind explaining to me how ? like is it changing how the names are presented? what is the * for ?

but i think the code broke the index matching for the name finding because im getting a no child even thought there is one ^

1) For inserting the data i'm looking into a pivot table and getpivotdata to fetch the info. If that doesn't work then maybe a index match...

2) I'm not sure why the hyperlinking isn't working...


3) Ok that's fine

4) just a spacing mistake thing because it copy them manually. I will fix that.

5) by trailing space you name before or after... i just centered them for asthetic purposes does it change anything ? if so i can put them aligned left.

you got any idea on how to hide the template when there is no 2, 3, 4 or 5th child to avoid.
like maybe hiding those columns when the index match for birthdays returns a ''no child" value ?

-A
 
Upvote 0
Hey Akuini,
Thanks for that!
1.
Thanks for that! it works would you mind explaining to me how ? like is it changing how the names are presented?

presented where? in the result? it will be the same as the template.
what is the * for ?
what "*"?

2.
but i think the code broke the index matching for the name finding because im getting a no child even thought there is one ^
It happens in your original copy & I don't know how to fix that ( actually my knowledge about formula is very basic :cry::cry:)

3.
I'm not sure why the hyperlinking isn't working...
Try in your original copy, say select A5 then hit the button, you'll see that A2 will get the hyperlink not A5.
But I think I can fix that later.

4.
just a spacing mistake thing because it copy them manually. I will fix that.
Ok, fix that & upload the new copy, so I can adjust my code.

5.
by trailing space you name before or after... i just centered them for asthetic purposes does it change anything ? if so i can put them aligned left.
The center aligning is fine, but you have 2 spaces in the end of all name, why?

6.
you got any idea on how to hide the template when there is no 2, 3, 4 or 5th child to avoid.
like maybe hiding those columns when the index match for birthdays returns a ''no child" value ?
I think I can do that.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,588
Members
449,039
Latest member
Arbind kumar

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