title: Looping through worksheets to convert range into table
body: <p>I am trying to create a looping procedure that goes through multiple worksheets and converts the data into a table. I think my code keeps breaking because obviously each array can only have one instance of "Table1". I have a couple of questions:</p>
  
  <p>1: is there a way to dynamically name each table. Ex: set the name of the table to the worksheet title?</p>
  
  <p>2: how can i create error handling code that exits the sub routine if there is already an existing table. EX. I have already run this on my existing workbook, but added a new sheet with raw data and still need to convert it to a table. </p>
  
  <p>Here is what I have so far, any and all help is appreciated (new to VBA)</p>
  
  <pre><code>Sub newTables()
  
  
  ' newTables Macro
  ' T
  '
  ' Keyboard Shortcut: Ctrl+Shift+T
  
  Dim rngSelectionRange As Range
  Set rngSelectionRange = ActiveSheet.Range(Selection.Address)
  
  For i = 1 To Worksheets.Count
  
      Worksheets(i).Range("A1").Select
      Range(Selection, Selection.End(xlDown)).Select
      Range(Selection, Selection.End(xlToRight)).Select
      'where it breaks
      ActiveSheet.ListObjects.Add(xlSrcRange, rngSelectionRange, , xlYes).Name = "Table1"
      'Range("Table1[#All]").Select
      'ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleLight2"
      'ActiveSheet.ListObjects("Employ").Name = "Employee_Data"
      If ActiveSheet.ListObjects.Count &gt; 1 Then
      End If
  
  Next i
  End Sub
  </code></pre>