2017-08-26 19 views
1

エラー450 "間違った数の引数または無効なプロパティの割り当て"が表示されます。エラーは関数の最後の行、最後の行 "End Function"で発生します。私は、任意のは、私がこれを引き起こしているもの見当もつかないので「Ifsにエンド」欠けて表示されていない。 "End Function"行のExcel VBA 450エラー

Function bpCreateDictionary(ByVal KeyColumn As String, ByVal ValueColumn As String, _ 
     Optional ByVal RowBegin As Long, Optional RowEnd As Long, _ 
     Optional ByVal DataWorksheet As String = "Sheet1", _ 
     Optional ByVal DataWorkbook As String, _ 
     Optional ByVal HandleDuplicates As String, _ 
     Optional ByVal KeepOpen As Boolean = False) As Dictionary 

    Application.ScreenUpdating = False 

    sCurrentActiveBook = ActiveWorkbook.Name 
    sCurrentActiveSheet = ActiveSheet.Name 

    Dim oDictionary As New Scripting.Dictionary 
    Dim lLastRow As Long 
    Dim lIncrementer As Long 
    Dim vKey As Variant 
    Dim vValue As Variant 

    If Not DataWorkbook = "" Then 
     oWorkbookName = bpGetFilenameFromPath(DataWorkbook) 
     Workbooks.Open (DataWorkbook) 
     Workbooks(oWorkbookName).Activate 
     sCurrentActiveExternalSheet = ActiveSheet.Name 
    End If 

    If Not DataWorksheet = "" Then 
     Worksheets(DataWorksheet).Activate 
    End If 

    If Not RowEnd = 0 Then 
     lLastRow = RowEnd 
    Else 
     lLastRow = bpLastRow(KeyColumn) 
    End If 

    If RowBegin = 0 Then 
     RowBegin = 1 
    End If 

    For lIncrementer = RowBegin To lLastRow 
     vKey = Cells(lIncrementer, KeyColumn) 
     vValue = Cells(lIncrementer, ValueColumn) 
      If HandleDuplicates = "Ignore" And oDictionary.Exists(vKey) Then 
       'Do Nothing and move to next row 
      Else 
       oDictionary.Add vKey, vValue 
      End If 
    Next lIncrementer 

    Set bpCreateDictionary = oDictionary 

    If Not oWorkbookName = "" Then 
     If Not KeepOpen = True Then 
      Worksheets(sCurrentActiveExternalSheet).Activate 
      Workbooks(oWorkbookName).Close SaveChanges:=False 
     End If 
    End If 

    Workbooks(sCurrentActiveBook).Activate 
    Worksheets(sCurrentActiveSheet).Activate 

    Application.ScreenUpdating = True 

End Function 

そして、その最後の行「エンド機能」に

は次のとおりです。この関数を参照

myDict = bpCreateDictionary("A", "B", 1, 10, "Sheet2", , "Ignore") 

デバッグ時にエラーが発生します。何がここで起こっているかもしれないかに関するアイデア?

+6

'設定しmyDict = bpCreateDictionary(...)'へあなたが持っているあなた

Set bpCreateDictionary = oDictionary 

機能でやった、気に入りましたか? – GSerg

+0

それはGSergだった、ありがとう! – user4333011

答えて

0

あなたは

Set myDict = bpCreateDictionary("A", "B", 1, 10, "Sheet2", , "Ignore"). 
+0

何度もこの同じ間違いを犯したことはありません。それを指摘してくれてありがとう! – user4333011