Array not passing to function

trough

Board Regular
Joined
Oct 26, 2010
Messages
55
I believe I have an array function IF statement that returns an array that I then try to pass to a user function to perform further processing of the data before returning to the workbook with the final array answer. However, it appears as though the user function isn't even getting ran. I set a break at the Redim line and it's never seen. It's like nothing is happening. I don't normally work with ranges or the passing of arrays so I've been researching but I am not having any luck. Could someone please tell me if I'm passing the data into and out of the function properly? Column H shows the result I desire in column E where the function is being used.


Excel 2010
ABCDEFGH
1Name
UserActiveUserList
2Smith, John
JSmithNo#VALUE!-JDoe
3Doe, JohnJDoeYes#VALUE!JDoeTCarver
4Jones, MaryMJonesNo#VALUE!--
5,SLincolnNo#VALUE!-
-
6Carver, TimTCarverYes#VALUE!TCarver-
7||
8Result of IF statement____________||
9|
10Desired result of UserList function__|

<tbody>
</tbody>
Sheet1

Array Formulas
CellFormula
E2:E6{=UserList(IF(A2:A6=", ","-",IF(C2:C6="No","-",B2:B6)))}
G2:G6{=IF(A2:A6=", ","-",IF(C2:C6="No","-",B2:B6))}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>




Code:
Option Explicit
Option Base 1


Function UserList(UName() As String)

' declare variables
Dim MyList() As String
Dim nList As Long
Dim i As Long
Dim j As Long

' get list size and dimension dynamic variable
nList = UBound(UName)
ReDim MyList(nList)

' populate dynamic list with names
j = 0
For i = 1 To nList
 If UName(i) <> "-" Then
  j = j + 1
  MyList(j) = UName(i)
 End If
Next i

' populate empty variable positions
If j < nList Then
 For i = j + 1 To nList
  MyList(i) = "-"
 Next i
End If

' write back to workbook
UserList = MyList()

End Function
 
Last edited:

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
try to make these changes

Code:
Function UserList([B]UName As Variant[/B]) 

' declare variables
Dim MyList() As String
Dim nList As Long
Dim i As Long
Dim j As Long

' get list size and dimension dynamic variable
nList = UBound(UName)
[B]ReDim MyList(1 To nList)[/B]

' populate dynamic list with names
j = 0
For i = 1 To nList
 If UName(i[B], 1[/B]) <> "-" Then
  j = j + 1
  MyList(j) = UName(i[B],[/B] [B]1[/B])
 End If
Next i

' populate empty variable positions
If j < nList Then
 For i = j + 1 To nList
  MyList(i) = "-"
 Next i
End If

' write back to workbook
UserList = MyList()

End Function
 
Last edited:
Upvote 0
Isn't this the same question you posted here?
 
Upvote 0
It works now except I had to change the last line to:

UserList = Application.Transpose(MyList)

This is interesting because I had read that when passing arrays the type had match exactly what the data type actually was (in this case String) and that I couldn't use variant. I had tried Variant before but missed treating it as a 2-dimensional array.

Thank you.
 
Upvote 0

Forum statistics

Threads
1,214,909
Messages
6,122,189
Members
449,072
Latest member
DW Draft

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