I'd suggest first creating a 'lookup' table, which maps ages to your required groups:
|
A |
B |
1 |
Age |
Age Group |
2 |
24 |
20-24 |
3 |
25 |
25-29 |
4 |
26 |
25-29 |
5 |
27 |
25-29 |
6 |
28 |
25-29 |
7 |
29 |
25-29 |
8 |
30 |
30-34 |
9 |
31 |
30-34 |
10 |
etc |
|
Then you can use a bit of code to replace age values with age group values:
Sub foo()
Dim c As Range, wsLookup As Worksheet, rngLookup As Range
'change these values to match your lookup table
Set wsLookup = Worksheets("Lookup Sheet")
Set rngLookup = wsLookup.Range("A1:B100")
For Each c In Selection 'change as necessary
c.Value = rngLookup.Find(what:=c.Value, lookat:=xlWhole).Offset(0, 1).Value
Next c
End Sub
Bookmarks