I have written a UDF which returns an array and want to display all of those values using an array formula on my sheet.
The UDF is:
My immediate window for the supplied range is below which is as expected and correct
The formula I am using is an array formula and I have also tried it as a normal formula but am not getting the results as expected
The cells where the formula is are just showing the same value (i.e. first in the array) over and over again.
Does anyone know where might be going wrong or how to get the expected output on the sheet from the formula I have written.
The UDF is:
Code:
Function GetDutyDetails(Rng As Range) As Variant
Dim ArraySize As Integer
ArraySize = Worksheets("ATCO").Range("atco_non_operational_duties").Rows.count
Dim DirArray() As Variant
ReDim DirArray(ArraySize)
DirArray = Worksheets("ATCO").Range("atco_non_operational_duties").Value
Dim Duties() As Variant
Dim i As Integer: i = 0
ReDim Duties(i)
For Each cell In Rng
'Debug.Print cell.Value
If IsInArray(cell.Value, DirArray) Then
'Debug.Print ("Cell value - " & cell.Value)
Else
'Debug.Print ("== Operational Duty (" & cell.Value & ") == ")
If IdentifyDutyType(cell.Value) = "Half AL" Then
Debug.Print ("** Half AL **")
Duties(i) = ("** Half AL **")
i = i + 1
ReDim Preserve Duties(i)
ElseIf IdentifyDutyType(cell.Value) = "Medical" Then
Debug.Print ("** Medical **")
Duties(i) = ("** Medical **")
i = i + 1
ReDim Preserve Duties(i)
ElseIf IdentifyDutyType(cell.Value) = "Early Arrival" Then
Debug.Print ("** Early Arrival **")
Duties(i) = ("** Early Arrival **")
i = i + 1
ReDim Preserve Duties(i)
ElseIf IdentifyDutyType(cell.Value) = "Duty Extension" Then
Debug.Print ("** Duty Extension **")
Duties(i) = ("** Duty Extension **")
i = i + 1
ReDim Preserve Duties(i)
ElseIf IdentifyDutyType(cell.Value) = "Ad Hoc Duty" Then
Debug.Print ("** Ad Hoc Duty **")
Duties(i) = ("** Ad Hoc Duty **")
i = i + 1
ReDim Preserve Duties(i)
End If
End If
Next cell
ReDim Preserve Duties(i - 1)
GetDutyDetails = Duties()
End Function
My immediate window for the supplied range is below which is as expected and correct
Code:
** Early Arrival **
** Ad Hoc Duty **
The formula I am using is an array formula and I have also tried it as a normal formula but am not getting the results as expected
Code:
=GetDutyDetails(ATCO!$K$16:ATCO!$K$20)
The cells where the formula is are just showing the same value (i.e. first in the array) over and over again.
Code:
** Early Arrival **
** Early Arrival **
** Early Arrival **
** Early Arrival **
** Early Arrival **
** Early Arrival **
** Early Arrival **
Does anyone know where might be going wrong or how to get the expected output on the sheet from the formula I have written.