Hi, I found this usefull function online, however I would like it to check 2 columns instead of one; this is the original:
I would like to make the code check column A for a "Y" as well as checking for sSearch.
Can someone please explain to me how to do that. I tried using and AND statement for the value of (1,A) but that didnt work... (i'm not very good at VBA).
Cheers
Code:
Function vlookupall(sSearch As String, rRange As Range, _
Optional lLookupCol As Long = 2, Optional sDel As String = ",") As String
'Vlookupall searches in first column of rRange for sSearch and returns
'corresponding values of column lLookupCol if sSearch was found. All these
'lookup values are being concatenated, delimited by sDel and returned in
'one string. If lLookupCol is negative then rRange must not have more than
'one column.
'Reverse("moc.LiborPlus.[URL unfurl="true"]www")[/URL] PB 16-Sep-2010 V0.20
Dim i As Long, sTemp As String
If lLookupCol > rRange.Columns.Count Or sSearch = "" Or _
(lLookupCol < 0 And rRange.Columns.Count > 1) Then
vlookupall = CVErr(xlErrValue)
Exit Function
End If
vlookupall = ""
For i = 1 To rRange.Rows.Count
If rRange(i, 1).Text = sSearch Then
If lLookupCol >= 0 Then
vlookupall = vlookupall & sTemp & rRange(i, lLookupCol).Text
Else
vlookupall = vlookupall & sTemp & rRange(i).Offset(0, lLookupCol).Text
End If
sTemp = sDel
End If
Next i
End Function
I would like to make the code check column A for a "Y" as well as checking for sSearch.
Can someone please explain to me how to do that. I tried using and AND statement for the value of (1,A) but that didnt work... (i'm not very good at VBA).
Cheers