2017-11-09 25 views
1

2D配列内の値が別の2D配列内に存在するかどうかを判断するのに役立つ関数が必要です。私はこのquestionで働いていた以前の機能をリファクタリングしようとしました。私はそのようなByref argument type mismatch(以後、私はByValステートメントを追加しました)と、私が直面している現在のエラーfunction call on left-hand side of assignmentに遭遇しました。テストなし2D配列内の値が別の2D配列内にある場合関数

Public aLogic As Variant 
Public Field_List(1 To 70, 1 To 10) As String, Field_No_of_Rows As Long 

Sub Implement_Mapping() 
Dim aMapRow As Integer, aMapCol As Integer 

    For aMapRow = LBound(aLogic, 1) To UBound(aLogic, 1) 
     For aMapCol = LBound(aLogic, 2) To UBound(aLogic, 2) 

      If IsInArrayByVal(aLogic(aMapRow, aMapCol), Field_List) = True Then 
       Debug.Print aLogic(aMapRow, aMapCol) 
        'For Each Break In ObjLSL 

        'Next 
      End If 
     Next aMapCol 
    Next aMapRow 

End Sub 

Function IsInArrayByVal(ByVal stringToBeFound As String, ByVal arr As Variant) As Boolean 
IsInArray = Not IsError(Application.Match(stringToBeFound, Application.Index(arr, 0, 1), 0)) 
+0

デバッグ/コンパイルを使用して、問題が発生したときに質問を更新します。例えば、 'Application.Match'は存在しません。 – Excelosaurus

+0

ここでいくつかの質問をしようとしているようです。通常、投稿ごとに1つの問題に集中する必要があります。 –

+1

@Excelosaurus、こちらをご覧ください:https://stackoverflow.com/questions/44159529/application-match-in-vbaしかし、Intellisenseでは表示されないことがあります。 –

答えて

3

が動作するには、次を修正する必要があります。

Function IsInArrayByVal(ByVal stringToBeFound As String, ByVal arr As Variant) As Boolean 
    IsInArray = Not IsError(Application.Match(stringToBeFound, Application.Index(arr, 0, 1), 0)) 
End Function 

へ:

Function IsInArrayByVal(ByVal stringToBeFound As String, ByVal arr As Variant) As Boolean 
    IsInArrayByVal = Not IsError(Application.Match(stringToBeFound, Application.Index(arr, 0, 1), 0)) 
End Function 

あなたはおそらく持っていますIsInArrayはコード内の別の場所で機能し、先ほど説明したエラーメッセージ、つまりにつながります。

+0

私はそれをキャッチしませんでした –

1

私の推測Field_List(1 To 70, 1 To 10) As StringField_List(1 To 70, 1 To 10) As Integerでなければならないことです。数値型と非数値型を比較す​​ると、型の不一致が発生します。

別の奇妙なことは、あなたがEnd Functionなければ

Function IsInArrayByVal(ByVal stringToBeFound As String, ByVal arr As Variant) As Boolean 
IsInArray = Not IsError(Application.Match(stringToBeFound, Application.Index(arr, 0, 1), 0)) 

を持っているということです。たぶんあなたはこの投稿にそれをコピーするのを忘れていましたが、もしそうでなければ、私はあなたに問題を与えることはかなり確信しています。

だから、それはする必要があります:あなたのコードの残りの部分を想定し

Function IsInArrayByVal(ByVal stringToBeFound As String, ByVal arr As Variant) As Boolean 

    IsInArrayByVal = Not IsError(Application.Match(stringToBeFound, Application.Index(arr, 0, 1), 0)) 

End Function