title: VBA : Using Public variables for other subs
body: <p>Excel-VBA. I want to create a variable that I will use in a couple of other subs later. Following other questions on this I declared the variable publicly</p>
  
  <pre><code>Public Counter As Integer
  </code></pre>
  
  <p>Then, I proceeded to give a value to the variable using a sub</p>
  
  <pre><code>Sub Count()
  Set sh2= ActiveWorkbook.Sheets("Sheet2")
  Set sh1 = ActiveWorkbook.Sheets("Sheet1")
  Dim rng As Range
  Dim trng As Range
  Set trng = sh2.Range("A4:HV4")
  
  For Each rng In trng
      If rng.Value = "Name" Then
      Counter = Range(rng, rng.End(xlToLeft)).Columns.count
      End If
  Next rng
  </code></pre>
  
  <p>If I try to test on the same sub which value count has e.g. </p>
  
  <pre><code>sh1.range("B1").value = counter
  </code></pre>
  
  <p>I get the right number.</p>
  
  <p>However, once I try calling it on another sub, the value is 0!</p>
  
  <pre><code>Sub Test()
  
  Range("F1").Value = counter
  
  end sub 
  </code></pre>
  
  <p>I have also tried calling the Count sub on my test sub, but also no result. </p>
  
  <p>Any ideas? Thanks!</p>