Select Case function to return multiple values against multiple ranges

Matei

New Member
Joined
Apr 2, 2012
Messages
24
I'm trying to create a formula/addin in vba which is basically a vlookup to return a company name against company numbers.




In a typical vlookup I will need to have a seperate table of information to vlookup against, but I need to use this function across multiple sheets at various times and having a long list of information always open isn't really an option




to make things more difficult, the company number could be in various cells.


the below is what I have so far but i've got stuck when it comes to adding multiple cells as variants.


if I do "IslikeNumber(A1)" it will return the correct result, but I need something which allows for multiple, optional cells "=IsLikeNumber(A1, B1, F1, Ax1)" etc.




Code:
Function IslikeNumber(inValue As Variant, Optional inValue2 As String, Optional InValue3 As String, _
Optional InValue4 As String, Optional InValue5 As String, Optional InValue6 As String, _
Optional InValue7 As String, Optional InValue8 As String, Optional InValue9 As String) As Variant






Select Case inValue




     Case "1a", "2b", "3c"
          IslikeNumber = "company1"
     


     Case "4d", "5e", "6f", "7g"
          IslikeNumber = ""company2"
     
     
     Case "8h", "9i", "10j", "11k"
      IslikeNumber = "company3"




'OTHERS
    Case Else
        IslikeNumber = "Other"




End Select






End Function


Also, there are thousands of company numbers for each company name. In the above I've removed most for easier reading.



any help anyone can offer will be greatly appreciated.
Matei
 
Last edited:

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,216,661
Messages
6,131,974
Members
449,692
Latest member
MAV57

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