VBA to Categorise based on columns

Argh_Work

New Member
Joined
Oct 17, 2023
Messages
11
Office Version
  1. 2013
Platform
  1. Windows
Hi All,
I was hoping that someone could please help me with some VBA code to automate a process.
I have 2 pages in my spread sheet the first looks like this:

A2B2C2D2E2
ID.TypeAGECategoryScore
669972159N3
132125524Y9
151515131N3
393838165Y56
787897323Y2

The second contains the below categories.
I'd like to automate the process so the information in sheet 1 is compared to the matrix in sheet 2 and on a third page the Id number is listed with the applicable code.

i.e
In the example of ID 669972 they are a type 1 their age is 59 and they are a N category their score is 3 therefore ID. 669972 = Code 130

In the example of ID 393838 they are a type 1 their age is 65 their category is Y and their score is 2 = ID 393838 Code 136

A2B2C2D2E2
TypeAge CategoryScoreCode
50-17Y123
518-64Y124
565+Y125
10-17Y>17126
10-17Y<17127
10-17Y0128
118-64N>14129
118-64N<14130
118-64N0131
118-64Y>14132
118-64Y<14133
118-64Y0134
165+Y>15135
165+Y<15136
165+Y0137
20-17Y>12138
20-17Y<12139
20-17Y0140
218-64Y>10141
218-64Y<10142
218-64Y0143
265+Y>11144
265+Y<11145
265+Y0146
30-17Y>12147
30-17Y<12148
30-17Y0149
318-64Y>11150
318-64Y<11151
318-64Y0152
365+Y>11153
365+Y<11154
365+Y0155
40-17Y>9156
40-17Y<9157
40-17Y0158
418-64Y>8159
418-64Y<8160
418-64Y0161
465+Y>9162
465+Y<8163
465+Y0164
90-17Y0165
918-64Y0166
965+Y0167

I'd really appreciate assistance it would make my work life so much easier.
Thanks
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
  1. Are you still using Excel 2013?

  2. Would you be open to slightly changing the layout of the second sheet if that made the process a bit easier?

  3. In the example below, what would be the result if their score was 17? Asking because your table only gives >17 and <17
In the example of ID 669972 they are a type 1 their age is 59 and they are a N category their score is 3 therefore ID. 669972 = Code 130

Similarly, down the bottom of your sheet 2 table you have a score section that shows >9 and <8. That doesn't allow for a score of 8 or 9 or anything in between.

BTW, are scores always whole numbers?
 
Upvote 0
Thanks for the response Peter.
I can definitely change the format of the sheets if it is easier.
Yes to excel 2013. (Organisational choice....)
Sorry it should be =<17 etc
We round up to whole numbers.
Thanks so much for considering the problem.
@Peter_SSs
 
Upvote 0
Thanks for the clarifications. My suggestions below may need a bit of tweaking but I think should allow a solution in the end.

First some changes to the second sheet.
  1. I have split the Age ranges into two columns. The yellow 200 values could be something else so long as they are at least as large as the greatest age you will ever have in the data. There is no actual need for the original age brackets column (B) but you may choose to keep it anyway.

  2. I have made the Score column into two columns so we can represent the relevant score ranges. The yellow 1000 values could be something else so long as they are at least as large as the greatest score you will ever have in the data. There is no actual need for the original score column (F) but you may choose to keep it anyway. In your sample data some of the score cells are empty or simply equal to zero. I wasn't certain what to do with those rows so they may need changing.
I have also assumed that the 'Code' column contains actual numbers, not numbers stored as text.

Argh_Work.xlsm
ABCDEFGHI
1
2TypeAgeAge StartAge EndCategoryScoreScore StartScore EndCode
350-17017Y01000123
4518-641864Y01000124
5565+65200Y01000125
610-17017Y>17181000126
710-17017Y<17117127
810-17017Y000128
9118-641864N>14151000129
10118-641864N<14114130
11118-641864N000131
12118-641864Y>14151000132
13118-641864Y<14114133
14118-641864Y000134
15165+65200Y>15161000135
16165+65200Y<15115136
17165+65200Y000137
1820-17017Y>12131000138
1920-17017Y<12112139
2020-17017Y000140
21218-641864Y>10111000141
22218-641864Y<10010142
23218-641864Y000143
24265+65200Y>11121000144
25265+65200Y<11111145
26265+65200Y000146
2730-17017Y>12131000147
2830-17017Y<12112148
2930-17017Y000149
30318-641864Y>11121000150
31318-641864Y<11111151
32318-641864Y000152
33365+65200Y>11121000153
34365+65200Y<11111154
35365+65200Y000155
3640-17017Y>9101000156
3740-17017Y<919157
3840-17017Y000158
39418-641864Y>891000159
40418-641864Y<818160
41418-641864Y000161
42465+65200Y>9101000162
43465+65200Y<819163
44465+65200Y000164
4590-17017Y000165
46918-641864Y000166
47965+65200Y000167
Sheet2


Then on the first sheet, try this formula.

Argh_Work.xlsm
ABCDEF
1
2ID.TypeAGECategoryScoreCode
3669972159N3130
4132125524Y9124
5151515131N3130
6393838165Y56135
7787897323Y2151
Sheet1
Cell Formulas
RangeFormula
F3:F7F3=SUMPRODUCT(--(B3=Sheet2!A$3:A$47),--(C3>=Sheet2!C$3:C$47),--(C3<=Sheet2!D$3:D$47),--(D3=Sheet2!E$3:E$47),--(E3>=Sheet2!G$3:G$47),--(E3<=Sheet2!H$3:H$47),Sheet2!I$3:I$47)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,173
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top