title: Excel VBA Macro with run-time error '1004'
body: <p>can anyone help me with this? for this particular function, it is getting run-time error 1004 for "sheet1.Range("a1:a" &amp; RowNbr).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=sheet1.Range("J1"), Unique:=True"</p>
  
  <p>this is the full codes:</p>
  
  <pre><code>Sub stock_exercise()
  Dim RowNbr As Long
  Dim uniqueticker As Long
  Dim totalvolume As String
  Dim r As Long
  Dim sheet1 As Worksheet
  
  Set sheet1 = ThisWorkbook.Sheets("A")'determine row count
  RowNbr = sheet1.Range("A1", sheet1.Range("A1").End(xlDown)).Rows.Count
  
  'copy and past unique ticker from column a to column j
  sheet1.Range("a1:a" &amp; RowNbr).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=sheet1.Range("J1"), Unique:=True
  
  sheet1.Range("J1").Value = "ticker"
  uniqueticker = sheet1.Range("j1", Range("j1").End(xlDown)).Rows.Count
  
  'sumif of each ticker
  For r = 2 To uniqueticker
      totalvolume = Application.SumIf(sheet1.Range("a1:a" &amp; RowNbr),     sheet1.Cells(r, 10), sheet1.Range("g1:g" &amp; RowNbr))
      sheet1.Cells(r, 11).Value = totalvolume
  Next r
  End Sub
  </code></pre>