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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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