'Select a table error: Range Object variable or With block variable not set

I am trying to select part of a table.

To select the whole table, I found the first cell (e.g. A1) to the last cell (e.g. C10) of the table.

I thought I could save the range A1:C10 by the following code -

last_row = Activesheet.Range("A1").End(xlDown).row
last_column = Activesheet.Range("A1").End(xlToRight).columnn

table = Activesheet.Range("A1:" & Cells(last_row ,last_column).Address)

The code is failing at the third line.
If I input Cells(last_row ,last_column).Address into the immediate window, it gives me the correct cell.
Is it because of the way I concatenated the range, and is there a better way of doing this?



Solution 1:[1]

It is possible to retrive the last row and column with UsedRange:

    last_row = ActiveSheet.UsedRange.Rows.Count
    last_column = ActiveSheet.UsedRange.Columns.Count

Solution 2:[2]

'try this to determine the last column 
 LastColumn = ActiveSheet.Cells(1, ActiveSheet.Columns.Count).End(xlToLeft).Column

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Xavier Junqué
Solution 2 ApisMel