Object Error - VBA

captainxcel

New Member
Joined
Jul 28, 2017
Messages
24
Hi everyone - Thanks in advance.
I'm trying to create a macro to resize 20 tables. The table names are in cells and the macro creates an array of these and then starts a resize loop. I'm getting an object error at: Set tableName = Codes(i). Any ideas of what I need to do here?
Thanks!

Sub resizeClientTables()
Dim sh As Worksheet
Set sh1 = ThisWorkbook.Worksheets("Lists")

Dim Codes(1 To 20) As String

'Create Array
Dim i As Long
For i = 1 To 20
Codes(i) = sh1.Range("A3").Offset(i).Value
Next i

'Define Vars
Dim sh2 As Worksheet
Dim tableName As String
Dim loTable As ListObject
Dim loRows As Integer, loColumns As Integer
Dim iNewRows As Integer, iNewColumns As Integer

'Get number of rows to add or delete
iNewRows = Application.InputBox("Enter a positive or negative amount of rows:", Type:=1)
iNewColumns = 0

'Cycle through tables and resize
For i = LBound(Codes) To UBound(Codes)
Set tableName = Codes(i)
Set sh2 = Sheets("Rebalance")
Set loTable = sh2.ListObjects(tableName)
loRows = loTable.Range.Rows.Count
loColumns = loTable.Tange.Columns.Count

loTable.Resize loTable.Range.Resize(loRows + iNewRows, loColumns + iNewColumns)
Next i

End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
63,988
Office Version
  1. 365
Platform
  1. Windows
You don't Set strings, only objects, so it should be
VBA Code:
tableName = Codes(i)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
63,988
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Forum statistics

Threads
1,144,364
Messages
5,723,939
Members
422,527
Latest member
TotalBeginner201

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top