0
votes

I am trying to execute the following code to copy columns from one table to another table in excel

Sub CopyData()
'
' CopyData Macro
'

'
    If Application.WorksheetFunction.CountA(Range("Table13[@Budget_Line_Id]")) <> 0 _
    Then Range("Table13[@Budget_Line_Id]").Delete

    'Select desired column to copy with destination option
    Range("Table1[[@Budget_Line_Id]]").Copy _
    Destination:=Range("Table13[[@Budget_Line_Id]]")
End Sub

I get a Method Range of object '_Global' Failed error at the first line

Could anyone please help resolving this issue

1

1 Answers

1
votes

@ refers to the current row, and results in error if the currently active cell is above or below the table.

Sub CopyData()
    If [CountA(Table13[Budget_Line_Id])] Then
        [Table1[Budget_Line_Id]].Copy [Table13[Budget_Line_Id]]
    End If
End Sub

https://msdn.microsoft.com/en-us/vba/excel-vba/articles/application-evaluate-method-excel