For some reason, I am having troubles in valuing this function: with 2 ranges in 2 different workbooks, the function is looking for matching cells and finding the column number of the matching cell in the 2-second range... but without any success. I've checked types, ranges, workbooks, etc...
Context:
Context:
- "my_range_A" is located in workbook 1, and call Function (located in same workbook 1). Address range: A1:C3;
- "anyRange " is located in workbook 2. Range address: A1:C3
Code:
dim my_varC as integer
my_varC = f_find_col_nbr (my_range_A, any_string)
VBA Code:
Public Function f_find_col_nbr(anyRange As Range, my_varA As String) As Integer
Dim my_counter As Integer
Dim varB As String
Dim my_col_index As Integer
Dim anyRange_count_cols As Integer
With workbooks(wkb).worksheets(wks).range(anyRange)
anyRange_count_cols = .columns.count
For my_counter = 1 To anyRange_count_cols
varB = .Cells(1, jp)
If varB = my_varA Then
f_find_col_nbr = jp
Else ' Other values.
'Debug.Print "Not found...looking for..."
End If
Next
End with
End Function