Excel Vba:Sub或Function未定义

时间:2022-11-06 09:40:01

I have the following code

我有以下代码

Sub CopyMacro()
'
' CopyData Macro
'
    Dim tableName As ListObject
    Set tableName = Worksheets("ToCopySheet").ListObjects(1)
    ListObjects("Table1").ListColumns("TaskUID").DataBodyRange.Copy tableName.ListColumns("TaskUID").DataBodyRange

End Sub

When I try to run this I get a compile error. Sub or Function not defined. I do not understand the issue here as I don't see anything wrong in this syntax.

当我尝试运行它时,我得到一个编译错误。 Sub或Function未定义。我不明白这里的问题,因为我在这个语法中没有看到任何错误。

The thing I'm trying to accomplish is to copy one column from one table to another table column in another sheet (ToCopySheet).

我想要完成的是将一列从一个表复制到另一个表中的另一个表列(ToCopySheet)。

Could someone please help resolve this error

请有人帮忙解决此错误

1 个解决方案

#1


3  

Maybe you mean

也许你的意思是

Sub CopyMacro()
'
' CopyData Macro
'
    Dim tableName As ListObject
    Set tableName = Worksheets("ToCopySheet").ListObjects(1)

    Dim ws As Worksheet
    Set ws = ActiveSheet
    ws.ListObjects("Table1").ListColumns("TaskUID").DataBodyRange.Copy tableName.ListColumns("TaskUID").DataBodyRange

End Sub

#1


3  

Maybe you mean

也许你的意思是

Sub CopyMacro()
'
' CopyData Macro
'
    Dim tableName As ListObject
    Set tableName = Worksheets("ToCopySheet").ListObjects(1)

    Dim ws As Worksheet
    Set ws = ActiveSheet
    ws.ListObjects("Table1").ListColumns("TaskUID").DataBodyRange.Copy tableName.ListColumns("TaskUID").DataBodyRange

End Sub