SUMIF in VBA using variable

CodyMonster

Board Regular
Joined
Sep 28, 2009
Messages
159
Hoping to get some help here.
Trying to get this sumif formula to get added to my sheet. However, it's throwing out a 1004 error.
Just need another set of eyes, if anyone has a second?


VBA Code:
Sub test()

Dim LastParagonRow As Long

LastParagonRow = Sheets("Paragon_CEBO_Data").Cells(Rows.Count, "A").End(xlUp).Row

Sheets("Output").Range("H2").Value = "=SUMIFS(Paragon_CEBO_Data!P$2:P""&LastParagonRow&"",Paragon_CEBO_Data!$H$2:$H""&LastParagonRow&"",$F2,Paragon_CEBO_Data!$B$2:$B""&LastParagonRow&"",$G2)"


End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
The "" are not needed around variables.

VBA Code:
Sub test()
    Dim LastParagonRow As Long

    LastParagonRow = Sheets("Paragon_CEBO_Data").Cells(Rows.Count, "A").End(xlUp).Row

    Sheets("Output").Range("H2").Formula = "=SUMIFS(Paragon_CEBO_Data!$P$2:$P" & LastParagonRow & ", Paragon_CEBO_Data!$H$2:$H" & LastParagonRow & ", $F2, Paragon_CEBO_Data!$B$2:$B" & LastParagonRow & ", $G2)"
End Sub
 
Upvote 0
Solution
I think you went a little overboard with the quotes.
VBA Code:
Sheets("Output").Range("H2").Formula = "=SUMIFS(Paragon_CEBO_Data!P$2:P" & LastParagonRow & ",Paragon_CEBO_Data!$H$2:$H" & LastParagonRow & ",$F2,Paragon_CEBO_Data!$B$2:$B " & LastParagonRow & ",$G2)"
Artik

Edit: Too late
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top