title: VBA public variables
body: <p>I am having trouble with the public i as intger portion of my code.
  I am using i to keep the value of my current row so i can use this range across
  my program. In my for loop it increments i so it will step through a column and search for v
  however when i try using "i" in another set of code "i" no longer has a value.
  I am not sure how global/public variables work in VBA or what is cause this error.</p>
  
  <p>the problem occurs int Sub "yes" , and sub "no"
  at the code</p>
  
  <pre><code>Cells(i,lcol).value=" ok " 
  </code></pre>
  
  <p>and </p>
  
  <pre><code>Cells(i,lcol).value = " updated "
  </code></pre>
  
  <p>1st set of code is as follows, which gets my value for "i"</p>
  
  <pre><code>Public V As Integer
  Public i As Integer
  
  Private Sub Enter_Click()
  Dim EmptyRow As Long
  
  'Audit will only search Master Sheet
  Worksheets("Master").Activate
  
  'Find empty row value so we can use that for limit of search
  With Sheets("Master")
       EmptyRow = .Range("A" &amp; Rows.Count).End(xlUp).Row + 1
  End With
  
  'i needs to be set to minimum limit
  'Begin loop of search
  For i = 12 To EmptyRow + 1
  
      If Cells(i, 1).Value = V Then  'AssetNum.Value Then
  
          'Go to compare userform to display
  
          Compare.AssetDisplay.Value = AssetNum.Value
          Compare.LocationDisply.Value = Cells(i - 1, 2).Value
          Compare.Show
  
       End If
    Next i
  
      'If i gets to emptyrow num then go to non found asset userform
      Unload Me
      NonFoundAsset.Show
  
   End Sub
  
  Private Sub UserForm_Initialize()
  
  'Read in value from asset num to be comapre in loop
  AssetNum.Value = V
  
  End Sub
  </code></pre>
  
  <p>the second set of code im trying to call "i" using the public variable and it has no value</p>
  
  <pre><code>Private Sub No_Click()
  
  Dim ws As Worksheet
  Dim lcol As Long
  
  'Make Master Sheet Active
   Worksheets("Master").Activate
  
  Set ws = ThisWorkbook.Sheets("Master")
  
  'Finds next empty column
  
    With ws
          lcol = .Cells(11, .Columns.Count).End(xlToLeft).Column - 1
    End With
  
  'If the displayed location is not the same as the actual location "No" will be
  'selected and the Change User Form will be displayed
  'The value under the current audit column will be displayed as updated
   Cells(i, lcol).Value = " Updated "
   Unload Me
   AuditChange.Show
  
  End Sub
  
  Private Sub Yes_Click()
  
   Dim ws As Worksheet
   Dim lcol As Long
  
  'Make Master Sheet Active
   Worksheets("Master").Activate
  
  Set ws = ThisWorkbook.Sheets("Master")
  
  'Finds next empty column
  
    With ws
          lcol = .Cells(11, .Columns.Count).End(xlToLeft).Column - 1
      End With
  
      'If the location displayed is correct "Yes" will be selected and
      'The value "ok" will be displayed in the current audit column
  
      Cells(i, lcol).Value = " Ok "
      Unload Me
      'Returns to Assetlookup to look for a new asset
      Assetlookup.Show
  End Sub
  </code></pre>
  
  <p>I appreciate any help, Im new to VBA and don't understand why this is not working.</p>