जब मैं एक्सेल से समारोह (एक सेल में) कहते हैं:कोड से कॉल किए जाने पर मेरी स्प्रेडशीट फ़ंक्शन अलग-अलग क्यों व्यवहार करती है?
=allVlookup(O24,A:D,3,"")
VBA
MsgBox allVlookup(Range("O24"), Range("A:D"), 3, "")
मैं अलग परिणाम प्राप्त के माध्यम से बनाम। एक्सेल से बुलाए जाने पर, मुझे केवल पहला मैच मिलता है, लेकिन जब समान पैरामीटर के साथ वीबीए टेस्ट सब से कॉल किया जाता है (उप-चलाने की अनुमति देने के लिए Range
को तर्कों को छोड़कर), मुझे पूर्ण परिणाम मिलते हैं (जो एक से अधिक है) ।
समारोह मैं उपयोग कर रहा हूँ है:
Public Function allVlookup(lookupRange As Range, tableRange As Range, colIndex As Integer, Optional delimiter As String = "") As String
Dim c As Range
Dim firstAddress As String
'MsgBox tableRange.Address ' this is correct
'With Sheets(4).Range("A1:C12").Columns(1)
'With Range("A1:C12").Columns(1)
'this doesn't allow things to work right either (???)
'Set tableRange = Range("A:D")
'Set lookupRange = Range("O24")
'search only the first column for matches
With tableRange.Columns(1)
Set c = .Find(what:=lookupRange.Value, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
'add the delimiter
If (allVlookup <> "") Then
allVlookup = allVlookup + delimiter
End If
'append value to previous value
allVlookup = allVlookup + c.Offset(0, colIndex).Value
Set c = .FindNext(c)
'exit conditions
'no match found
If (c Is Nothing) Then
Exit Do
'we're back to start
ElseIf (c.Address = firstAddress) Then
Exit Do
End If
Loop
End If
End With
End Function
मैं एक नुकसान में हूँ समझाने के लिए क्यों यह हो रहा है।
आउटपुट को समान होने के लिए मैं क्या कर सकता हूं?
से नहीं कहा जा सकता है, मैं इसे एक बग के साथ रह सकता हूं। परेशान, लेकिन, जानना अच्छा है। – enderland