Execute IF for each row and replace row value if condition is true

I have a column of ages that I need to convert into certain string values, depending on the value in each row.

For example: If a row in ‘age’ column has a value between 20 and 29 I need it to replace the value with “Twenties”, If a row in ‘age’ column has a value between 30 and 39 I need it to replace the value with “Thirties” … and so on.

This can be done by replacing the values, or inserting strings in another column, doesn’t matter to me, I just need a way to iterate thru each row and insert / replace the value in corresponding rows.

Assuming your data is in column C, in A1:A9 enter the category values 10,20,…,90 and in B1:B9 the category strings Teens,Twenties,…,Nineties. In D1 enter the formula

=VLOOKUP(C1;$A$1:$B$9;2)

and copy-paste that down to D2:…

Note that ages below 10 will result in #N/A error, and all ages above 90 will result in Nineties. Add categories as necessary. The category values MUST be in strictly ascending order.

Insert the starting age for each age group along with name of the group in tabular form in a separate sheet, sorted by age, and use VLOOKUP() on that table.

See the attached file:Age grouping.ods

Of course, essentially the same solution which erAck already proposed.

Adding the bottom category from zero and the top one with an impossible (well, highly unlikely at least) age is one way to handle the potential errors he mentions. If those groups are not relevant, (i.e. entries “outside the field” indicate a mistake), an error handling function may be a better choice.