Excel VBA 450“上的错误;“结束函数”;线
我收到一个错误450“参数数量错误或属性赋值无效”。错误发生在函数的最末端,即最后一行“end function”。我看不到任何缺失的“结束如果”,因此我不知道是什么原因导致了这种情况:Excel VBA 450“上的错误;“结束函数”;线,vba,excel,function,Vba,Excel,Function,我收到一个错误450“参数数量错误或属性赋值无效”。错误发生在函数的最末端,即最后一行“end function”。我看不到任何缺失的“结束如果”,因此我不知道是什么原因导致了这种情况: myDict = bpCreateDictionary("A", "B", 1, 10, "Sheet2", , "Ignore") 其中引用了此函数: Function bpCreateDictionary(ByVal KeyColumn As String, ByVal ValueColumn As S
myDict = bpCreateDictionary("A", "B", 1, 10, "Sheet2", , "Ignore")
其中引用了此函数:
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
最后一行“End Function”是调试时出错的地方。你对这里可能发生的事情有什么想法吗?就像你在
Set bpCreateDictionary = oDictionary
你必须
Set myDict = bpCreateDictionary("A", "B", 1, 10, "Sheet2", , "Ignore").
就像你在函数中所做的那样
Set bpCreateDictionary = oDictionary
你必须
Set myDict = bpCreateDictionary("A", "B", 1, 10, "Sheet2", , "Ignore").
Set myDict=bpCreateDictionary(…)
?就是这样,谢谢<代码>设置myDict=bpCreateDictionary(…)?就是这样,谢谢!我不能告诉你我犯了多少次同样的错误,谢谢你指出!我不能告诉你我犯了多少次同样的错误,谢谢你指出!