title: Dynamic button - Runtime error 1004 - Unable to get the Buttons property of the Worksheet class
body: <p>Hi I'm getting "Runtime error 1004 - Unable to get the Buttons property of the Worksheet class" and it's coming from line near the bottom <code>Set b = Worksheets("Form").Buttons(Application.Caller) 'references button</code>. </p>
  
  <p>I'm basically trying to copy the data in the column next to a dynamic button that appears next to the fully expanded fields of a pivot table. I've got the buttons appearing fine, I just need them to copy the data in the adjacent cell to a list in another sheet when that particular button is clicked.</p>
  
  <pre><code>Sub buttonGenerator()
  
  Dim btn As Button
  Application.ScreenUpdating = False
  ActiveSheet.Buttons.Delete
  Dim t As Range
  Dim size As Long
  
  size = Worksheets("Form").PivotTables("Pivottable1").TableRange2.Rows.Count 'returns number of rows in expanding pivot table
  
  For i = 2 To size Step 1 'cycles through from row 2 to last row of pivot table
      If Not IsEmpty(Worksheets("Form").Range(Cells(i, 4), Cells(i, 4))) Then 'only shows button if last col of pivot table has data
        Set t = Worksheets("Form").Range(Cells(i, 5), Cells(i, 5))
        Set btn = Worksheets("Form").Buttons.Add(t.Left, t.Top, t.Width, t.Height)
        With btn
          .OnAction = "btnS" 'call btnS subroutine
          .Caption = "Button" &amp; i 'button label
          .Name = "Button" &amp; i 'button name
          End With
      End If
  
  Next i
  
  Application.ScreenUpdating = False
  
  End Sub
  
  
  Public Sub btnS()
  
  Dim b As Object
  Dim r As Integer
  Dim c As Integer
  
  Set b = Worksheets("Form").Buttons(Application.Caller) 'references button
  With b.TopLeftCell 'returns row and col of button pushed
  r = .row
  c = .col
  End With
  
  origin = Range(r, c)
  dest = Worksheets("Form Output").Range(Cells(1, 1))
  dest.Value = origin.Value
  
  End Sub
  </code></pre>