title: Excel - VBA : pass variable from Sub to Userform
body: <p>I have read and applied solution I found on similar topics but nothing seem to work in my case. </p>
  
  <p>So, I want to pass a variable from one sub of my Module1 to a userform. It's a string called "provinceSugg".  </p>
  
  <p><strong>Here is the relevant part of my code :</strong>  </p>
  
  <pre><code>Public provinceSugg As String
  
  Sub probaCity()
  [...]
  If province = "" And city &lt;&gt; "" Then
  provinceSugg = sCurrent.Cells(p, db_column).Offset(0, 1).Value
  UserForm2.Label1 = "Do you mean " &amp; city &amp; " in " &amp; provinceSugg &amp; " ?"
  UserForm2.Label1.TextAlign = fmTextAlignCenter
  UserForm2.Show
  Else
  End If
  
  End Sub
  </code></pre>
  
  <p><strong>And then in my userform code :</strong>  </p>
  
  <pre><code>Private Sub userformBtn1_Click()
  
  MsgBox provinceSugg
  sMain.Range("J6").Value = provinceSugg
  
  End Sub
  </code></pre>
  
  <p><strong>When I run my program :</strong> </p>
  
  <p><strong>1/</strong> I have the content of provinceSugg showing in the MsgBox called from my sub (so there is a provinceSugg, it's not an empty variable).<br>
  <strong>2/</strong> The MsgBox called from the userform is empty (so passing the value failed) and my program crashes when running " sMain.Range("J6").Value = provinceSugg" with something like "Error 424 Object Required" (so the variable failed to pass to the userform).</p>
  
  <p>I tried all the stuff I found on forum and here (different ways to indicate that provinceSugg is a public variable but still crashing...).</p>
  
  <p>Thanks in advance for your help !</p>