Make Array available to a function

pitaszek

Board Regular
Joined
Jul 20, 2012
Messages
85
Hi Guys,

Do you know any way?

The function is to Vlookup the array and return a name of the boss based on employees name.

I tried to declare the Array as a public but this does not work.

Maybe there is a way to pass a constant parameter to a function in a form of variant array?

I tried something like, maybe you can use that as a basis:

Code:
'People() is an 2d array
Function FindTheBoss(SalesEN As Variant, People() As Variant) As String


    For i = 1 To UBound(People)
    
                If People(i, 2) = Person Then
                   FindTheBoss = People(i, 1)
                End If
            
    Next i


End Function

Regards,
Witek
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
This worked for me

Code:
Public People As Variant
Const Boss = "Mary"


Sub FindPerson()


  Dim p As String
  Dim i As Long
  People = Range("B4:C8")
  
  p = FindTheBoss()
  Debug.Print p
  
End Sub


Function FindTheBoss()
  Dim i As Long
  
  For i = 1 To UBound(People)
    If People(i, 1) = Boss Then
      FindTheBoss = People(i, 2)
      Exit Function
    End If
  Next i
    
End Function
 
Upvote 0

Forum statistics

Threads
1,223,891
Messages
6,175,229
Members
452,621
Latest member
Laura_PinksBTHFT

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