Table name issue

mtterry

New Member
Joined
Aug 9, 2016
Messages
40
The code pasted below is resulting in a table name that starts with an underscore, and I can't understand why - any help would be appreciated.

ActiveSheet.ListObjects.Add(xlSrcRange, Range([A1].End(xlDown), [A1].End(xlToRight)), , xlYes).Name = _
Month(pmtDate) & "_" & Year(pmtDate) & "_" & uploadType
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,351
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
A table name can't begin with a number, so Excel is adding an underscore for you.
 

Johnny Thunder

Well-known Member
Joined
Apr 9, 2010
Messages
578
Office Version
2016
Platform
MacOS
This part of your code ").Name = _" is defining the name being given so if you remove that underscore it will go away.

The code pasted below is resulting in a table name that starts with an underscore, and I can't understand why - any help would be appreciated.

ActiveSheet.ListObjects.Add(xlSrcRange, Range([A1].End(xlDown), [A1].End(xlToRight)), , xlYes).Name = _
Month(pmtDate) & "_" & Year(pmtDate) & "_" & uploadType
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,351
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
This part of your code ").Name = _" is defining the name being given so if you remove that underscore it will go away.
That's a VBA line continuation character, not part of the name string being assigned.
 

mtterry

New Member
Joined
Aug 9, 2016
Messages
40
Correct, if I made it all one line without the continuation _ I have the same problem
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,351
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
Yes, because of the number at the start.
 

mtterry

New Member
Joined
Aug 9, 2016
Messages
40
So I don't suppose you have an idea of how to get rid of that leading underscore?
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,351
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
Don't start the name with a number. Table names follow the same rules as defined names - they have to start with a letter or underscore.
 

Forum statistics

Threads
1,082,305
Messages
5,364,406
Members
400,801
Latest member
julievandermeulen

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top