finnrichard
New Member
- Joined
- Sep 12, 2014
- Messages
- 2
Dear fellow forum users,
I am trying to make a lookup function in VBA that returns the nth occurence in a table. So far I have written the following code, but it doesn't work. I am new to VBA, can anyone please help me?
Function FindNthOccurence(lookup_value As String, mytable As Range, Nth As Integer) As String
Dim i As Integer
Dim currentdindex As Integer
currentindex = 0
For i = 1 To mytable.Rows.Count
If mytable(i, 1) = lookup_value Then
currentindex = currentindex + 1
If currentindex = Nth Then
FindNthOccurence = currentindex
Next i
I am trying to make a lookup function in VBA that returns the nth occurence in a table. So far I have written the following code, but it doesn't work. I am new to VBA, can anyone please help me?
Function FindNthOccurence(lookup_value As String, mytable As Range, Nth As Integer) As String
Dim i As Integer
Dim currentdindex As Integer
currentindex = 0
For i = 1 To mytable.Rows.Count
If mytable(i, 1) = lookup_value Then
currentindex = currentindex + 1
If currentindex = Nth Then
FindNthOccurence = currentindex
Next i