0

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.

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

Could someone please help resolve this error

1 Answer 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
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for the answer. I am getting a subscript out of range error when I use this code
I do not know your excel sheet but you need to have a table1 with a column TaskUID and on your second sheet "ToCopySheet" the first table should also contain a column "TaskUID"
no sorry, it was my mistake with the table names etc. now its resolved

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.