I am trying to create "my first" formula-function, but can't get it to work.
It returns an error.
First I tested the function as a standard module and rendered the output in the debug console to test the outcome. All worked well.
However I can't get the same module to work as a function
Below the function:
It is called in this way =TEST(val;rng)
| resulting in #value!
Function TEST(val As String, rng As Range) As String
Dim a, b As String
Dim cel, itm, tst, s As Range
Dim row, l, i As Integer
'-----------------------------------------------------
a = ""
b = ""
val = "ROX.RFL.avi.Rmd.ice"
Set rng = Range(Sheets("DGR").Cells(3, 3), Cells(3, 34))
'-----------------------------------------------------
For Each cel In rng.Cells
If InStr(UCase(val), UCase(cel)) Then
a = a & UCase(cel) & ","
row = Sheets("DGR").Cells(Rows.Count, cel.Column).End(xlUp).row
If row <> 3 Then
For Each itm In Range(Sheets("DGR").Cells(4, cel.Column), Cells(row, cel.Column))
b = b & UCase(itm) & ","
Next itm
End If
End If
Next cel
'-----------------------------------------------------
For Each tst In Split(a, ",")
If InStr(b, tst) > 0 Then TEST = tst
Next tst
End Function
Below the tested function as a module: (this worked properly)
Sub MKDGR()
Dim val, a, b As String
Dim rng, cel, itm, tst, s As Range
Dim row, l, i As Integer
'-----------------------------------------------------
a = ""
b = ""
val = "ROX.RFL.avi.Rmd.ice"
Set rng = Range(Sheets("DGR").Cells(3, 3), Cells(3, 34))
'-----------------------------------------------------
For Each cel In rng.Cells
If InStr(UCase(val), UCase(cel)) Then
a = a & UCase(cel) & ","
row = Sheets("DGR").Cells(Rows.Count, cel.Column).End(xlUp).row
If row <> 3 Then
For Each itm In Range(Sheets("DGR").Cells(4, cel.Column), Cells(row, cel.Column))
b = b & UCase(itm) & ","
Next itm
End If
End If
Next cel
'-----------------------------------------------------
For Each tst In Split(a, ",")
If InStr(b, tst) > 0 Then Debug.Print tst
Next tst
End Sub