任何想法如何确定个人属于Excel的年龄组? [英] Any ideas how to determine what age group an individual belongs in Excel?
问题描述
我在Excel电子表格中有2列。
第一列标题称为AGE,第二列标题称为Age_Group。
AGE列中的年龄介于18和45之间。
可能有多行具有相同的年龄。
我的任务是确定某个年龄段的年龄组别,然后打印出该年龄组。
例如,如果有人的年龄是18岁,我想使用IF声明或CASE声明来确定18岁在18到24岁之间,然后将该值放入Age_Group列为18-24。
<如果年龄是19岁,则会在Age_Broup列中的18-24组中。
如果年龄列中的年龄介于25和29之间那么他们将在Age_Group列为25-29。
这是一个例子:
AGE AGE_GROUP
18 18-24
19 18- 24,
25 25-29
28 25-29
如果你请分享一些代码,我可以使用它来计算休息,直到我们达到45。
我对Excel VBA不好。对于IF或CASE声明的任何帮助将不胜感激。
这是一个VBA代码:但是,那个Excel VLOOKUP。 :)
-
首先将模块添加到VBA项目。
-
复制以下
代码。
Option Explicit
函数whatAgeGroup(ByVal i As Integer)As String
选择案例i
案例IsEmpty(i)
whatAgeGroup =没有年龄输入
案例18至24:
whatAgeGroup =18-24
案例25到29
whatAgeGroup =25-29
案例30到34
whatAgeGroup =30-34
案例35到39
whatAgeGroup =35- 39
案例40到44
whatAgeGroup =40-44
案例是> = 45
whatAgeGroup =45及以上
案例Else
whatAgeGroup =WhatGroup?
结束选择
结束功能
- 输入功能名称在单元格中,并输入,如图所示。
I have 2 columns in an Excel spread sheet.
First column header is called AGE and the second column header is called Age_Group.
The ages in the AGE column are between 18 and 45.
There could be multiple rows with same age.
I am tasked with determining what age group a certain age falls into and then print out that age group.
For instance, if someone’s age is 18, I would like to use IF statement or CASE statement to determine that age 18 is between 18 and 24 and then put that value into Age_Group column as 18-24.
If age is 19, again, it will fall into the group of 18-24 in Age_Group column.
If the age in the Age column falls between 25 and 29, then they will be in Age_Group column as 25-29. Here is an example:
AGE AGE_GROUP
18 18-24
19 18-24,
25 25-29
28 25-29
If you would be kind to share some code, I can use it to calculate the rest till we reach 45.
I am not good with Excel VBA. Any assistance with IF or CASE statement would be greatly appreciated.
Here is a VBA code: But surely you are better off with that Excel VLOOKUP. :)
First add module to a VBA project.
Copy the following
code.
Option Explicit
Function whatAgeGroup(ByVal i As Integer) As String
Select Case i
Case IsEmpty(i)
whatAgeGroup = "No Age Entered"
Case 18 To 24:
whatAgeGroup = "18-24"
Case 25 To 29
whatAgeGroup = "25-29"
Case 30 To 34
whatAgeGroup = "30-34"
Case 35 To 39
whatAgeGroup = "35-39"
Case 40 To 44
whatAgeGroup = "40-44"
Case Is >= 45
whatAgeGroup = "45 and Above"
Case Else
whatAgeGroup = "WhatGroup?"
End Select
End Function
- enter the function name in a cell and enter, as per the image shown.
这篇关于任何想法如何确定个人属于Excel的年龄组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!