Hi, i am working on a user defined function.
The function has 2 tasks:
1st to identify the name range out of 21 name ranges basis user input (user input 1) and use it in set range = variable (this is where i need help)
I think here directly referring to the range name also will need indirect function support which i am again not able to do and need help.
2nd then to match the string (user input 2) in the name range defined above and return the adjacent columns (which i am able to do).
The function code i have written does pretty much the task 2, but with only one name range which stays static.
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 - the problem i think is in this code row
'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
The function has 2 tasks:
1st to identify the name range out of 21 name ranges basis user input (user input 1) and use it in set range = variable (this is where i need help)
I think here directly referring to the range name also will need indirect function support which i am again not able to do and need help.
2nd then to match the string (user input 2) in the name range defined above and return the adjacent columns (which i am able to do).
The function code i have written does pretty much the task 2, but with only one name range which stays static.
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 - the problem i think is in this code row
'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