EMPTY Cell Value property when there is cell content

FANAIT

New Member
Joined
Sep 16, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
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:

  1. "my_range_A" is located in workbook 1, and call Function (located in same workbook 1). Address range: A1:C3;
  2. "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




1663407907453.png
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
You have argument in your function called anyrange, which is of type range
but then you use it as it would be the address of some range in wkb book wks sheet (address, so a string like "$A$1", not a range as such).

So start with replacing
VBA Code:
   With workbooks(wkb).worksheets(wks).range(anyRange)
with
VBA Code:
   With anyRange
 
Upvote 0
You have argument in your function called anyrange, which is of type range
but then you use it as it would be the address of some range in wkb book wks sheet (address, so a string like "$A$1", not a range as such).

So start with replacing
VBA Code:
   With workbooks(wkb).worksheets(wks).range(anyRange)
with
VBA Code:
   With anyRange
Hi, Kaper. Yes, indeed, have replaced it.... but still getting the same value: empty!
 
Upvote 0
But what is jp value here?
VBA Code:
varB = .Cells(1, jp)

How you really call the function what is the expected result?
Because in the description text you mentioned two ranges, whoile in the function you compare just one value with (some cells in a) range
 
Upvote 0
Solution
But what is jp value here?
VBA Code:
varB = .Cells(1, jp)

How you really call the function what is the expected result?
Because in the description text you mentioned two ranges, whoile in the function you compare just one value with (some cells in a) range
jp value is the column index number matching the cell address: the function is looping in the horizontal way, and when cells(1, jp).value matches the same cell content (value) then the passed argument, then the function result will be "jp2 (ie, the column number).
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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