Setting up a Case Select structure using a reference table

A Guy Named Robby

New Member
Joined
Oct 19, 2016
Messages
25
I have lots of Case Select scenarios set up. I'm going to have to add a lot more. A greatly condensed sample is below. How can I recreate this scenario using a reference table?

Beginning on row 84 to the end of the data, it's comparing what's in column O (college names) to hundreds/thousands of cases. If it finds a match, it enters a specific digit in column N.

Code:
Sub NumberFillIn()
Dim LastRow As Long
Dim i As Long
LastRow = Range("O" & Rows.Count).End(xlUp).Row
For i = 84 To LastRow

Select Case Range("O" & i)

Case "New York University", "NYU", "New York Univ.", "New York Univ"
Range("N" & i) = "1"

Case "Abraham Lincoln University"
Range("N" & i) = "2"

Case "Mississippi College"
Range("N" & i) = "3"

Case "Piedmont College"
Range("N" & i) = "4"

Case "Minnesota State University"
    Select Case Range("P" & i)
    Case "Bemidji"
    Range("N" & i) = "5"
    Case "Moorhead"
    Range("N" & i) = "6"
    Case "St Cloud", "St. Cloud"
    Range("N" & i) = "7"
    Case "Mankato"
    Range("N" & i) = "8"
    End Select

End Sub
 
Sorry again! With this code, it looks like the matches are case sensitive. For example, "new york university" won't be matched to "New York University." Help?
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Fuzzy matching is always tricky. There are lots of ways to do it, but they tend to get more and more complicated, and end up less and less effective. There's usually a break-even point somewhere where you have to accept you're just going to get some mismatches.

For just checking case, it's easy enough to tell the InStr function to do a text compare, which doesn't care about case. Change:

Code:
If InStr(MyOptions(j, 2), Match1) > 0 And InStr(MyOptions(j, 3), Match2) > 0 Then

to

Code:
If InStr(1, MyOptions(j, 2), Match1, vbTextCompare) > 0 And InStr(1, MyOptions(j, 3), Match2, vbTextCompare) > 0 Then
 
Upvote 0

Forum statistics

Threads
1,217,388
Messages
6,136,302
Members
450,002
Latest member
bybynhoc

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