I have this code below that will auto select a range. Does anyone know how I can add code to create a table to the selected range?
Thanks!
Sub DynamicRan
Use the following Excel VBA code snippet to add the Table
object corresponding to selected Range
:
Dim objTable As ListObject
Set objTable = ActiveSheet.ListObjects.Add(xlSrcRange, Selection, , xlYes)
You can also apply optional styling to the added Table
object like shown below:
objTable.TableStyle = "TableStyleMedium2"
More details available at MSDN: https://msdn.microsoft.com/en-us/library/office/ff823155.aspx
Hope this will help.