title: How to use an object that's in another module?
body: <p>completely new to VBA here. I have a problem getting my code running. In the first module, it works fine and creates a new Excel sheet formatted with the data I want. In the second module I want to be able to create a table that can sort it. I ran the code and I got a run-time error of '91': Object variable or with block variable not set.</p>
  
  <p>If anybody could offer some advice, would greatly appreciate it, thanks!</p>
  
  <p>1st Module:</p>
  
  <pre><code>Option Explicit
  
  Public wsFormatted As Workbook
  
  
  Sub FormatData()
  
  'Create new worksheet named "Formatted"
  
  Set wsFormatted = ThisWorkbook.Sheets.Add
  
  wsFormatted.Name = "Formatted"
  
  End Sub
  </code></pre>
  
  <p>Second Module:</p>
  
  <pre><code>Option Explicit
  
  Sub createTable()
  
  Dim Formatted As Workbook
  
  Formatted.ListObjects.Add(xlSrcRange, Range("A1:M105"), , xlYes).Name = "SortedTable"
  
  End Sub
  </code></pre>