Accessing a table using a variable

I’ve spent ages trying to figure this out, but I’m obviously missing something, I’m trying to insert into a table using a variable for the tablename, the code looks something like this

--Create 3 empty tables  
TableNum1 = {}  
TableNum2 = {}  
TableNum3 = {}  
  
--Get a random number 1,2 or 3  
ranNum = math.random(3)  
  
--Concat the number onto TableNum store in variable tableName  
tableName = 'TableNum'..ranNum  
  
--Try to insert into the table  
table.insert(tableName,'whatever')   

I get the error:
bad argument #1 to ‘insert’ (table expected, got string)

Any ideas, I feel like I’m missing something, but I’ve no idea what
[import]uid: 36590 topic_id: 7957 reply_id: 307957[/import]

easy way:
[lua]local tables = {}
–Create 3 empty tables
tables[1] = {}
tables[2] = {}
tables[3] = {}

–Get a random number 1,2 or 3
local ranNum = math.random(3)

–Try to insert into the table
table.insert(tables[ranNum],‘whatever’) [/lua] [import]uid: 6645 topic_id: 7957 reply_id: 28326[/import]

hard way: :stuck_out_tongue:
[lua]–Create 3 empty tables
TableNum1 = {}
TableNum2 = {}
TableNum3 = {}

–Get a random number 1,2 or 3
ranNum = math.random(3)

–Concat the number onto TableNum store in variable tableRef
assert(loadstring(“tableRef = TableNum”…ranNum))()

–Try to insert into the table
table.insert(tableRef,‘whatever’)
print(TableNum3[1])[/lua] [import]uid: 6645 topic_id: 7957 reply_id: 28327[/import]

Many thanks Jmp, I thought I’d tried the first method, but must have been doing something wrong.
[import]uid: 36590 topic_id: 7957 reply_id: 28359[/import]