Problem setting ListObject names using a variable ending with a number

Malenki

New Member
Joined
May 3, 2014
Messages
3
Hello. I am having troubles with a sub routine that selects a range and converts that range to a list object. I am able to successfully create the ListObject, but when it sets the name it appends an "_" at the end of the table name if the variable ends in a number.

For example:

Dim tableName As String
tableName = "abc123"
Set Rng = Worksheets(dataInsertWorksheet).range(Worksheets(dataInsertWorksheet).range("A1"), Worksheets(dataInsertWorksheet).range("A1").SpecialCells(xlLastCell))
Worksheets(dataInsertWorksheet).ListObjects.Add(xlSrcRange, Rng, , xlYes).Name = tableName

The above code will create the ListObject and assign the name "abc123_" to it. If I set the tableName variable to just "abc" it will not append an underscore at the end. I'm not sure why this happens because table names CAN end in a number, it is only when I dynamically create the ListObject through VBA that it will not accept numbers at the end of the name.

Thank you for any suggestions

 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
abc123 is a valid cell reference, and so is not a valid name.
 
Upvote 0

Forum statistics

Threads
1,223,715
Messages
6,174,064
Members
452,542
Latest member
Bricklin

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
Back
Top