title: Declaring a public variable across modules
body: <p>I'm trying to establish a variable <code>LastRow</code> in Module 1, which can be used in other subs and modules. Below is a simplified version of whats in my actual workbook. 
      - One sub to call the others, 
      - One sub to create a public variable,
      - And another sub in a different module with a formula relying on the variable in <code>Sub CreateVariable</code>. </p>
  
  <p>I've already received a lot of help on here and from what I've read online declaring a public variable should be pretty straightforward... but I'm not getting it. Can anyone help? Thanks in advance!</p>
  
  <p>Module 1</p>
  
  <pre><code>Sub CallOthers()
  
  Call CreateVariable
  Call AddFormula
  
  End Sub
  </code></pre>
  
  <p>Module 1 </p>
  
  <pre><code>Public LastRow As Long
  
  Sub CreateVariable()
  
  Dim ws As Worksheet
  Set ws = Worksheets("Variance")
  LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
  
  End Sub
  </code></pre>
  
  <p>Module 2 </p>
  
  <pre><code>Sub AddFormula()
  
  ws.Range("D2:D" &amp; LastRow).FormulaR1C1 = "=RC[-2]-RC[1]"
  
  End Sub
  </code></pre>