title: VBA/Macro code to get the value of textbox
body: <pre><code>Sub CopyRandomRows()
  
   Windows("sample rnd.xlsm").Activate
      Rows("1:1").Select
      Selection.Copy
      Application.CutCopyMode = False
      Selection.Copy
      Windows("rnd sample draft.xlsm").Activate
      Sheets("Random Sample").Select
      Rows("1:1").Select
      ActiveSheet.Paste
  
  
    Dim source As Range, target As Range, randCount&amp;, data(), value, r&amp;, rr&amp;, c&amp;
  
  
    Set source = Workbooks("sample rnd.xlsm").Worksheets("Sheet1").Range("A2:L5215")
  
    Set target = Workbooks("rnd sample draft.xlsm").Worksheets("Random Sample").Range("A2")
  
    randCount = 5
  
    data = source.value
  
  
    For r = 1 To randCount
      rr = 1 + Math.Round(VBA.rnd * (UBound(data) - 1))
      For c = 1 To UBound(data, 2)
        value = data(r, c)
        data(r, c) = data(rr, c)
        data(rr, c) = value
      Next
    Next
  
  
    target.Resize(randCount, UBound(data, 2)) = data
  
  End Sub
  </code></pre>
  
  <p>This is my code. My problem is that I can only change the number of data i want if i change the code <code>randCount = 5</code>. I want to be able to use my TextBox and use it for defining how many data to get. I tried <code>randCound = TextBox1.value</code> and <code>randCount = TextBox1.Text</code> but does not seem to work. What am i missing? How do i get it work. thanks in advance</p>