title: Passing variable to another sub in a for loop if
body: <p>Having the error below in my code shown below,</p>
  
  <blockquote>
    <p>Compile Error</p>
    
    <p>Wrong Number of of arguments or invalid property assignment</p>
  </blockquote>
  
  <pre><code>Public Sub ListBox1_Click()
  
      Dim ShNameRow As Integer
      For i = 0 To ListBox1.ListCount - 1
  
          If ListBox1.Selected(i) = True Then
  
              Set T1 = Range("A" &amp; i + 13).Resize(26 - i, 1)
              Set T2 = Range("E" &amp; i + 13).Resize(26 - i, 2)
              Set T3 = Range("K" &amp; i + 13).Resize(26 - i, 1)
              Set y = Application.Union(T1, T2, T3)
              y.Select
              Selection.Copy
  
  
              ShNameRow = 13 + i
              'Error with passing this variable
              CopyData_Click (ShNameRow)
  
          End If
      Next i
  
  End Sub
  
  Private Sub CopyData_Click()
      'Testing variable
      MsgBox (ShNameRow)
  End Sub
  </code></pre>
  
  <p>-</p>
  
  <h2>UPDATE</h2>
  
  <p>I tried both that example of passing variable from one sub to another because I feel is more applicable with my code.</p>
  
  <p>Public Sub ListBox1_Click()</p>
  
  <pre><code>Dim ShNameRow As Integer
  For i = 0 To ListBox1.ListCount - 1
  
      If ListBox1.Selected(i) = True Then
  
          Set T1 = Range("A" &amp; i + 13).Resize(26 - i, 1)
          Set T2 = Range("E" &amp; i + 13).Resize(26 - i, 2)
          Set T3 = Range("K" &amp; i + 13).Resize(26 - i, 1)
          Set y = Application.Union(T1, T2, T3)
          y.Select
          Selection.Copy
  
  
          ShNameRow = 13 + i
          'Error with passing this variable
          CopyData_Click (ShNameRow)
  
      End If
  Next i
  
  End Sub
  
  Private Sub CopyData_Click(ListboxShNameRow As Integer)
  MsgBox (ListboxShNameRow)
  End Sub
  </code></pre>
  
  <p>Which brings another compile error on, displayed by block quote below</p>
  
  <pre><code>Private Sub CopyData_Click(ListboxShNameRow As Integer)
  </code></pre>
  
  <blockquote>
    <p>Procedure declaration does not match description of event or procedure having the same name</p>
  </blockquote>