briancross
New member
- Local time
- Today, 18:39
- Joined
- Sep 1, 2009
- Messages
- 7
Hello,
I am trying to create a user-defined function that accepts a string (ID), scans cells in a column (L) for the value "1", checks to see if the cell in the same column row immediately above equals ID, and returns a value stored in the row above, and 24 columns to the right. Returning the value that corresponds to the first occurrence of the conditions is fine.
A mess, I know...hopefully you can understand what I'm trying to do. Basically I'm sorting the data a certain way and using subtotal-count to find unique occurrences.
Here is what I have, if it runs at all I get #VALUE!
I am trying to create a user-defined function that accepts a string (ID), scans cells in a column (L) for the value "1", checks to see if the cell in the same column row immediately above equals ID, and returns a value stored in the row above, and 24 columns to the right. Returning the value that corresponds to the first occurrence of the conditions is fine.
A mess, I know...hopefully you can understand what I'm trying to do. Basically I'm sorting the data a certain way and using subtotal-count to find unique occurrences.
Here is what I have, if it runs at all I get #VALUE!
Code:
Public Function FINDACCT(ID As String) As String
Dim r As Range
For Each r In Range("L:L")
If r.Value = 1 And r.Offset(-1, 0).Value = ID Then
FINDACCT = r.Offset(-1, 24).Value
Exit Function
Else
FINDACCT = "Not Found"
End If
Next
End Function