Hi, I have a UDF I nicked from the internet, which works great, however:
I have one sheet that is the "input" worksheet.
I have 2 lookup sheets that use the "vlookupall" UDF to create a list of products that meet the criteria in these 2 sheets from the list provided in the input sheet.
One of the 2 lookup sheets refreshs the Vlookupall code when the variables in that sheet are modified, the other sheet (using the exact same code) doesn't.
However NEITHER of the lookup sheets update the UDF when the input sheet is updated.
I believe all the variables have to be in the argument for a UDF to update but as I only just grasp the basics of what this code is doing (and i'm not brialliant with VBA) I don't know how to fix this (my thoughts are that perhaps the "sDel" should somehow be in the argument?
If it helps, I don't need sDel to be anything other than "," (e.g. it doesn't need to be a variable).
I tried removing it completely but that started all my concacenations with "," at the begining which I don't want if possible.
I could make it all work by just filling down the forumula before the lookup sheets are printed or saved but it woulden't show the user real time info (which is something I REALLY don't want to happen), I don't want to use the volitile code as everytime the input form is changed it takes about 20 seconds before the user can do anything (without interupting the refreshing).
So the formula is:
=vlookupall(B6,'CHECK WEIGHER SHEET.xls'!rRange,2,", ")
The code is:
Cheers for any help.
I have one sheet that is the "input" worksheet.
I have 2 lookup sheets that use the "vlookupall" UDF to create a list of products that meet the criteria in these 2 sheets from the list provided in the input sheet.
One of the 2 lookup sheets refreshs the Vlookupall code when the variables in that sheet are modified, the other sheet (using the exact same code) doesn't.
However NEITHER of the lookup sheets update the UDF when the input sheet is updated.
I believe all the variables have to be in the argument for a UDF to update but as I only just grasp the basics of what this code is doing (and i'm not brialliant with VBA) I don't know how to fix this (my thoughts are that perhaps the "sDel" should somehow be in the argument?
If it helps, I don't need sDel to be anything other than "," (e.g. it doesn't need to be a variable).
I tried removing it completely but that started all my concacenations with "," at the begining which I don't want if possible.
I could make it all work by just filling down the forumula before the lookup sheets are printed or saved but it woulden't show the user real time info (which is something I REALLY don't want to happen), I don't want to use the volitile code as everytime the input form is changed it takes about 20 seconds before the user can do anything (without interupting the refreshing).
So the formula is:
=vlookupall(B6,'CHECK WEIGHER SHEET.xls'!rRange,2,", ")
The code is:
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
Cheers for any help.