Is it possible to make the vba code below a UDF function? Instead of running macro with F8 everytime, I'd like to use it with a UDF function only for specific cells? Thanks!
Code:
Sub Intervals() Dim r As range, C As range
With Cells(1).CurrentRegion
With .Offset(1).Resize(.Rows.Count - 1)
For Each r In .Cells
Set C = .Find(r.Value, r, , 1, , , 2)
If (C.Address <> r.Address) * (C.Row > r.Row) Then
r.Offset(, 6) = C.Row - r.Row - 1
Else
r.Offset(, 6) = "na"
End If
Next
End With
End With
End Sub
Last edited: