Version

Add(String,Boolean,WorksheetTableStyle) Method

Formats a region as a table and adds an associated WorksheetTable to the collection.
Syntax
'Declaration
 
Public Function Add( _
   ByVal region As String, _
   ByVal tableHasHeaders As Boolean, _
   Optional ByVal tableStyle As WorksheetTableStyle _
) As WorksheetTable

Parameters

region
The region to format as a table.
tableHasHeaders
A value which indicates whether the top row of the region contains the headers for the table.
tableStyle
The WorksheetTableStyle to apply to the table or null to use the Workbook.DefaultTableStyle.

Return Value

The WorksheetTable created the represent the formatted table for the region.
Exceptions
ExceptionDescription
System.InvalidOperationException The owning worksheet has been removed from its workbook.
System.ArgumentNullExceptionregion is null or empty.
System.ArgumentExceptionregion is not a valid region address in the workbook's cell reference mode.
System.ArgumentExceptionThe specified tableStyle does not exist in the CustomTableStyles or StandardTableStyles collections.
System.InvalidOperationExceptionThe region contains one or more cells from another WorksheetTable.
System.InvalidOperationExceptionThe region contains one or more cells which have a multi-cell ArrayFormula applied.
System.InvalidOperationExceptionThe region contains one or more cells which are part of a WorksheetDataTable.
Remarks

When the table is created, the specified tableStyle will be applied to the value.

When the table is created, the column names will be taken from the cells in the header row if tableHasHeaders is True. If it is False, the column names will be generated and the cells for the header row will be inserted into the worksheet.

The column names are unique within the owning WorksheetTable. If, when the table is created, there are two or more columns with the same name, the second and subsequent duplicate column names will have a number appended to make them unique. If any cells in the header row have a non-string value, their value will be changed to a string (the current display text of the cell). If any cells in the header row have no value, they will be given a generated column name.

If the region partially contains any merged cell regions, they will be removed from the worksheet and the table region will be expanded to include all cells from the merged region.

Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also