can anyone help me with this? for this particular function, it is getting run-time error 1004 for "sheet1.Range("a1:a" & RowNbr).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=sheet1.Range("J1"), Unique:=True"
this is the full codes:
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" & 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" & RowNbr), sheet1.Cells(r, 10), sheet1.Range("g1:g" & RowNbr))
sheet1.Cells(r, 11).Value = totalvolume
Next r
End Sub
RowNbr
if it fails? – Axel RichterCodeName
in the same format. I'd use something likewksOne
in place ofsheet1
. May not solve your issue though. – shrivallabha.redij