Ok got it. here is the code with code tags
Function lookupdiv(dimd As String, dimtech As String) As Variant
Dim rngs As Range
Dim m As Integer
Dim dimrange As Range
'--step 1 to identify the name range
Select Case dimtech
Case "2G", "3G", "General", "Combined"
dimrange = "Dim_2G3G"
Case "LTE"
dimrange = "Dim_LTE"
Case "Fixed"
dimrange = "Dim_Fixed"
Case Else
dimrange = "0"
End Select
'--- Load the table (range) from the global name
'--- the problem is in the below code line where i do not know how to set rngs to
'-----multiple names basis some user input. the below variable does not work and
'------ the return value for function is #value!
Set rngs = ActiveWorkbook.Names(dimrange).RefersToRange
'step 2 to look into the name range for string match
'--- Iterate through all members in the table
'--- (skip first header row),
For m = 2 To rngs.Rows.Count
If (dimd = rngs(m, 1)) Then
'--- A match has been found. Load data end exit the function
lookupdiv = rngs(m, 3)
Exit Function
End If
Next m
'--- if the exeution reach this point, there was no match
'--- Return "error" value
lookupdiv = 0
End Function
Bookmarks