我不断在这个子目标上获得对象:
Set RowNum = Sheets("Sheet3").ListObjects("Table1").ListColumns(1).Count
任何额外的帮助也将受到赞赏。我试图根据我正在处理的表的每一行的第一列单元格值从一个表复制并粘贴到另一个表,并将其与包含我需要的数据的表进行比较
Private Sub ECRList_Click()
Dim RowName As String
Dim ColName As String
Dim Collist As Range
Dim Namelist As Range
Dim RowNum As Integer
'Dim ColNum As Integer
Set Collist = Sheets("Sheet3").ListObject("Table1").HeaderRowRange 'creates an array that contains the table header cell names
Set Namelist = Sheets("Sheet3").ListObjects("Table1").ListColumns(1).Range 'creates an array that contains the first row cell names of the table
Set RowNum = Sheets("Sheet3").ListObjects("Table1").ListColumns(1).Count
For Each ColName In Collist 'iterate through each name in column header array
For Each RowName In Namelist 'iterate through each name in row name list
For RowNum = 1 To Namelist.UBound 'supplies an accurate array length
If Sheets("Sheet2").ListObjects("Table3").DataBodyRange(RowNum, "Column1").Value = Sheet1.ListObjects("Table1").DataBodyRange(RowNum, "ECR_No").Value Then 'compares the text of both of tables first rows
Sheets("Sheet2").ListObjects("Table3").ListRow(RowNum).Select
Sheets("Sheet2").ListObjects("Table3").ListRow(RowNum).Copy 'copies the row from table 3
Sheets("Sheet3").ListObjects("Table1").ListRow(RowNum).Select
Sheets("Sheet3").ListObjects("Table1").ListRow(RowNum).Paste 'pastes the row from table 3 too table 2
'Next ColNum
End If
Next RowNum
Next RowName
Next ColName
End Sub
答案 0 :(得分:0)
RowNum
不是对象变量。 Set
关键字仅在分配给对象变量时使用。
删除Set
关键字。
RowNum = Sheets("Sheet3").ListObjects("Table1").ListColumns(1).Count
错误消息意味着无法编译/评估语句,因为赋值的左侧不是对象类型,因为在使用Set
关键字时需要这样做(在这种情况下,您会还需要确保赋值语句的右侧也返回一个对象类型。