I'm creating a macro form in Word VBA that allows users to enter a week and a weight value which will calculate a percentile for them. I'm building this off of a table from a book that looks like this (Sorry, I'm not sure how to add tables to Stack Overflow questions yet):
Percentile 10th 50th 90th
Week1........3....12....34
Week2........5....17....39
Week3........8....21....42
Currently my VBA code looks like this:
If Week = 1 then
If Weight < 3 then
Selection.TypeText "less than 10th percentile for age"
ElseIf Weight = 3 then
Selection.TypeText "10th percentile for age"
ElseIf Weight < 12 then
Selection.TypeText "less than 50th percentile for age"
ElseIf Weight = 12 then
Selection.TypeText "50th percentile for age"
ElseIf Weight < 34 then
Selection.TypeText "less than 90th percentile for age"
ElseIf Weight = 34 then
Selection.TypeText "90th percentile for age"
ElseIf Weight > 34 then
Selection.TypeText "greater than 90th percentile for age"
End If
ElseIf Week = 2 then
If Weight < 5 then
Selection.TypeText "less than 10th percentile for age"
...
The table is actually much bigger than 3 columns and 3 rows, so you can imagine this is very tedious. The table itself is not to be visible to the user, but coded behind the scenes. I'm wondering if instead of typing out all the code like I've done above, if there's a way to add a table to this so that future maintenance of the values is more straightforward. Thank you!
I'm using Word 2016.