Referencing Excel2007 Tables

MrEPM

New Member
Joined
Aug 19, 2009
Messages
3
I have a worksheet with several tables defined and need to find out information about the tables and data contained in the tables using basic Excel and VBA.

The referenced table is named tlObjectNames
<TABLE style="WIDTH: 433pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=576 border=0><COLGROUP><COL style="WIDTH: 94pt; mso-width-source: userset; mso-width-alt: 4571" width=125><COL style="WIDTH: 37pt; mso-width-source: userset; mso-width-alt: 1792" width=49><COL style="WIDTH: 64pt; mso-width-source: userset; mso-width-alt: 3108" width=85><COL style="WIDTH: 238pt; mso-width-source: userset; mso-width-alt: 11593" width=317><TBODY><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-RIGHT: white 0.5pt solid; BORDER-TOP: #f0f0f0; FONT-WEIGHT: 700; FONT-SIZE: 11pt; BACKGROUND: #820024; BORDER-LEFT: #f0f0f0; WIDTH: 94pt; COLOR: white; BORDER-BOTTOM: white 1.5pt solid; FONT-FAMILY: Calibri; HEIGHT: 15pt; TEXT-DECORATION: none; text-underline-style: none; text-line-through: none; mso-pattern: #820024 none" width=125 height=20>cdObjectNames</TD><TD class=xl68 style="BORDER-RIGHT: white 0.5pt solid; BORDER-TOP: #f0f0f0; FONT-WEIGHT: 700; FONT-SIZE: 11pt; BACKGROUND: #820024; BORDER-LEFT: #f0f0f0; WIDTH: 37pt; COLOR: white; BORDER-BOTTOM: white 1.5pt solid; FONT-FAMILY: Calibri; TEXT-DECORATION: none; text-underline-style: none; text-line-through: none; mso-pattern: #820024 none" width=49>cdONOrder</TD><TD class=xl68 style="BORDER-RIGHT: white 0.5pt solid; BORDER-TOP: #f0f0f0; FONT-WEIGHT: 700; FONT-SIZE: 11pt; BACKGROUND: #820024; BORDER-LEFT: #f0f0f0; WIDTH: 64pt; COLOR: white; BORDER-BOTTOM: white 1.5pt solid; FONT-FAMILY: Calibri; TEXT-DECORATION: none; text-underline-style: none; text-line-through: none; mso-pattern: #820024 none" width=85>cdObjectType</TD><TD class=xl68 style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; FONT-WEIGHT: 700; FONT-SIZE: 11pt; BACKGROUND: #820024; BORDER-LEFT: #f0f0f0; WIDTH: 238pt; COLOR: white; BORDER-BOTTOM: white 1.5pt solid; FONT-FAMILY: Calibri; TEXT-DECORATION: none; text-underline-style: none; text-line-through: none; mso-pattern: #820024 none" width=317>cdONLenght</TD></TR><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-RIGHT: white 0.5pt solid; BORDER-TOP: #f0f0f0; FONT-WEIGHT: 400; FONT-SIZE: 11pt; BACKGROUND: #ff6792; BORDER-LEFT: #f0f0f0; COLOR: #3c3c3c; BORDER-BOTTOM: white 0.5pt solid; FONT-FAMILY: Calibri; HEIGHT: 15pt; TEXT-DECORATION: none; text-underline-style: none; text-line-through: none; mso-pattern: #FF6792 none" height=20>fnPrjAssumptions</TD><TD class=xl68 style="BORDER-RIGHT: white 0.5pt solid; BORDER-TOP: #f0f0f0; FONT-WEIGHT: 400; FONT-SIZE: 11pt; BACKGROUND: #ff6792; BORDER-LEFT: #f0f0f0; COLOR: #3c3c3c; BORDER-BOTTOM: white 0.5pt solid; FONT-FAMILY: Calibri; TEXT-DECORATION: none; text-underline-style: none; text-line-through: none; mso-pattern: #FF6792 none">1</TD><TD class=xl68 style="BORDER-RIGHT: white 0.5pt solid; BORDER-TOP: #f0f0f0; FONT-WEIGHT: 400; FONT-SIZE: 11pt; BACKGROUND: #ff6792; BORDER-LEFT: #f0f0f0; COLOR: #3c3c3c; BORDER-BOTTOM: white 0.5pt solid; FONT-FAMILY: Calibri; TEXT-DECORATION: none; text-underline-style: none; text-line-through: none; mso-pattern: #FF6792 none">Field</TD><TD class=xl68 style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; FONT-WEIGHT: 400; FONT-SIZE: 11pt; BACKGROUND: #ff6792; BORDER-LEFT: #f0f0f0; COLOR: #3c3c3c; BORDER-BOTTOM: white 0.5pt solid; FONT-FAMILY: Calibri; TEXT-DECORATION: none; text-underline-style: none; text-line-through: none; mso-pattern: #FF6792 none">#VALUE!</TD></TR><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-RIGHT: white 0.5pt solid; BORDER-TOP: #f0f0f0; FONT-WEIGHT: 400; FONT-SIZE: 11pt; BACKGROUND: #ffb3c9; BORDER-LEFT: #f0f0f0; COLOR: #3c3c3c; BORDER-BOTTOM: white 0.5pt solid; FONT-FAMILY: Calibri; HEIGHT: 15pt; TEXT-DECORATION: none; text-underline-style: none; text-line-through: none; mso-pattern: #FFB3C9 none" height=20>fnPrjBU</TD><TD class=xl68 style="BORDER-RIGHT: white 0.5pt solid; BORDER-TOP: #f0f0f0; FONT-WEIGHT: 400; FONT-SIZE: 11pt; BACKGROUND: #ffb3c9; BORDER-LEFT: #f0f0f0; COLOR: #3c3c3c; BORDER-BOTTOM: white 0.5pt solid; FONT-FAMILY: Calibri; TEXT-DECORATION: none; text-underline-style: none; text-line-through: none; mso-pattern: #FFB3C9 none">2</TD><TD class=xl68 style="BORDER-RIGHT: white 0.5pt solid; BORDER-TOP: #f0f0f0; FONT-WEIGHT: 400; FONT-SIZE: 11pt; BACKGROUND: #ffb3c9; BORDER-LEFT: #f0f0f0; COLOR: #3c3c3c; BORDER-BOTTOM: white 0.5pt solid; FONT-FAMILY: Calibri; TEXT-DECORATION: none; text-underline-style: none; text-line-through: none; mso-pattern: #FFB3C9 none">Field</TD><TD class=xl68 style="BORDER-RIGHT: #f0f0f0; BORDER-TOP: #f0f0f0; FONT-WEIGHT: 400; FONT-SIZE: 11pt; BACKGROUND: #ffb3c9; BORDER-LEFT: #f0f0f0; COLOR: #3c3c3c; BORDER-BOTTOM: white 0.5pt solid; FONT-FAMILY: Calibri; TEXT-DECORATION: none; text-underline-style: none; text-line-through: none; mso-pattern: #FFB3C9 none">#VALUE!</TD></TR></TBODY></TABLE>

COL cdObjectNames contain names of other tables
I want to calculate the number of rows of the table named in the first COL and store it in the COL named cdONLength

Problem #1
I use the following formula in a cell to find the number of rows in a table
=Rows(tlObjectNames) and it returns the correct number of rows.

If I replace the table name with a cell reference containing the name of the table, the calculation returns a value of 1
Cell A1 contains the text tlObjectNames
=Rows(A1) returns 1

How can I get the formula to evaluate correctly?

Problem #2
I'm getting #Value! errors when passing a string reference to a function call. The function is...

Public Function GetObjectLength(ObjectName As String) As Integer
Dim Object As ListObject

GetObjectLength = 0
Set Object = ActiveWorkbook.Worksheets("Tables").ListObjects(ObjectName)
MsgBox (Object.ListRows.Count)
GetObjectLength = Object.ListRows.Count

End Function

The function work using a cell formula of =GetObjectLenght("tlObjectNames")

I get the #Value! error in the cell if I change the formula to reference a cell containing the name of the table.

Cell A2 contains the text tlObjectNames

=GetObjectLenght(A2) returns #Value!

What could be causing the error?
 
Last edited:

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Using cell formula of =INDIRECT(F26) returns a #Ref! error until I use this formual version =INDIRECT("F26") where it returns the text.

If I use =ROWS(INDIRECT("F26")) it returns a value of 1 again.
 
Upvote 0
<HR style="COLOR: #ffffff; BACKGROUND-COLOR: #ffffff" SIZE=1> <!-- / icon and title --><!-- message -->
The formual of =INDIRECT(F26) returns a works if the value in cell F26 contanins text specifying another cell

F26=A1
A1= Me

=INDIRECT(F26) returns the text Me
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

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