将一个Variant数组传递给sub,“Expected:=”

我发现了一个函数,使用VBA将logging追加到Excel表格中。 我已经实现了它,但我不熟悉Variant数据types。 我做了一些研究,并试图使用它,因为我会在VB中的数组,但我不断得到一个奇怪的错误,它期望=符号。

在这里输入图像描述

以下是非截graphics式的代码:

 Sub AddDataRow(tableName As String, Values() As Variant) Dim sheet As Worksheet Dim table As ListObject Dim col As Integer Dim lastRow As Range Set sheet = ActiveWorkbook.Worksheets("Sheet1") Set table = sheet.ListObjects.Item(tableName) 'First check if the last row is empty; if not, add a row If table.ListRows.Count > 0 Then Set lastRow = table.ListRows(table.ListRows.Count).Range For col = 1 To lastRow.Columns.Count If Trim(CStr(lastRow.Cells(1, col).Value)) <> "" Then table.ListRows.Add Exit For End If Next col End If 'Iterate through the last row and populate it with the entries from values() Set lastRow = table.ListRows(table.ListRows.Count).Range For col = 1 To lastRow.Columns.Count If col <= UBound(Values) + 1 Then lastRow.Cells(1, col) = Values(col - 1) Next col End Sub Sub btnNewGateway_Click() pName = Application.InputBox("Enter New Participant Name", "New Participant") Worksheets("TemplateGateway").Copy After:=Worksheets("TemplateGateway") ActiveSheet.Name = pName + " Gateway" Dim Values() v(0) = pName v(1) = "Gateway" v(2) = Today() AddDataRow ("tblOverview",????) End Sub 

你需要使用

调用AddDataRow(tbloverview,v)