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

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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,215,083
Messages
6,123,020
Members
449,092
Latest member
ikke

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