I have the following table:
I need to fill the Group column with A, B, … using the age of the person and matching to Age Ranges.
So John, with age 5, would get the Group A. I was looking at the VLookup and HLookup functions.
The problem is that I am not sure if this is possible because of the Age Ranges: 0-7, 8-14, etc.
Do I need VBA for this?
Yes, VLOOKUP is the way to go,and there is no need for VBA. Here’s the setup:
Couple of things to notice.
The break points for the lookup are the lower bound of each group range
the lookup range itself is sorted
the third argument of the lookup is TRUE (the default) which means the function does a range rather than an exact lookup.
I prefer @chuff’s answer but since this is SO you could use code such as:-
Sub Macro1() Range("C2").Select ActiveCell.FormulaR1C1 = _ "=IF(RC[-1]>60,""E"",IF(RC[-1]>18,""D"",IF(RC[-1]>14,""C"",IF(RC[-1]>7,""B"",""A""))))" Selection.Copy Range("B2").Select Range(ActiveCell, ActiveCell.End(xlDown)).Offset(0, 1).Select ActiveSheet.Paste End Sub
assuming you want
A for John in