Home » excel » excel – Sumifs – sum of column ignoring N/A

# excel – Sumifs – sum of column ignoring N/A

Posted by: admin May 14, 2020 Leave a comment

Questions:

I am having trouble with an error code 1004. I am attempting to have a SUMIF formula in my VBA code. My objective is to Sum Column F from F2 to the lastrow. the column has Vlookup values that include “#N/A”. The formula used without VBA is

`=SUMIF(F2:F3509, "> 0")`

My attempted formula in VBA is

``````lastRow = Range ("A1048576").End(xlup).Row
Range("D" & lastrow) = "=SUMIF(F2:F, ""> 0""" & lastrow & ")"
``````

. Any help would be much appreciated. Thank you very much. Matt

How to&Answers:

Try

``````Lastrow = Range("A1048576").End(xlUp).Row + 1
Range("D" & Lastrow) = "=SUMIF(F2:F" & Lastrow & "," & Chr(34) & "> 0" & Chr(34) & ")"
``````

### Answer：

If you want to sum all the rows your last row must be from F column. If your column A has different number of elementos than F, that will not work.

You can also use SUMPRODUCT

``````lastrow = Range("F1048576").End(xlUp).Row
mRange = "F2:F" & lastrow
Range("D" & lastrow) = "=SUMPRODUCT(--(" & mRange & " >  0 ), " & mRange & " ) "
``````