Macro function Sumifs will not identify "some" alphanumeric criteria data

mskipwith

New Member
Joined
May 29, 2015
Messages
3
Hello,

I am pretty new to excel vba, so please bare with me. Thank you.

I just learned how to enter a function Sumifs into vba excel, and it worked fine until I entered my 3rd criteria, which is an alphanumeric character (including zeros), and it would not complete the full sum function for that last criteria. Here is the code I entered, and the highlighted blue data is the criteria it would not enter:

*Note: I am using very large data, 23 columns, +11k rows.

Dim oblRangePLL1 As Range
Dim oblRangeLO1 As Range
Dim oblRangeFP1 As Range
Dim oblRangeMNAmt1 As Range

Set oblRangePLL1 = Workbooks("S_DATA.xlsx").<wbr>Sheets("OBL").Range("A2", Workbooks("S_DATA.xlsx").<wbr>Sheets("OBL").Range("A2").End(<wbr>xlDown))
Set oblRangeLO1 = Workbooks("S_DATA.xlsx").<wbr>Sheets("OBL").Range("B2", Workbooks("S_DATA.xlsx").<wbr>Sheets("OBL").Range("B2").End(<wbr>xlDown))
Set oblRangeFP1 = Workbooks("S_DATA.xlsx").<wbr>Sheets("OBL").Range("G2", Workbooks("S_DATA.xlsx").<wbr>Sheets("OBL").Range("G2").End(<wbr>xlDown))
Set oblRangeMNAmt1 = Workbooks("S_DATA.xlsx").<wbr>Sheets("OBL").Range("J2", Workbooks("S_DATA.xlsx").<wbr>Sheets("OBL").Range("J2").End(<wbr>xlDown))




Range("H26").Formula = WorksheetFunction.SumIfs(<wbr>oblRangeMNAmt1, oblRangePLL1, "0968A1", oblRangeLO1, "15", oblRangeFP1, "QSQ0P00Y11")

Thank you for your help in this matter.

mskip
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
You can't enter a formula in H26 that way. Do you want the result of the SumIfs to be returned to H26 or do you want the actual Sumifs formula in that cell?
 
Upvote 0
You can't enter a formula in H26 that way. Do you want the result of the SumIfs to be returned to H26 or do you want the actual Sumifs formula in that cell?

Either way, the sum range and all the criteria ranges must contain the same number of rows. The way you are setting those ranges, that may not be the case. Depends on where End(xlDown) is for each range.
 
Upvote 0
You can't enter a formula in H26 that way. Do you want the result of the SumIfs to be returned to H26 or do you want the actual Sumifs formula in that cell?


Hi JoeMo,

I want the result of the SumIf function to be returned to H26.
 
Upvote 0
Either way, the sum range and all the criteria ranges must contain the same number of rows. The way you are setting those ranges, that may not be the case. Depends on where End(xlDown) is for each range.

What is the best way to set the ranges for each set of criteria. I am open to doing this another way if possible. Thanks.

mskip
 
Upvote 0
What is the best way to set the ranges for each set of criteria. I am open to doing this another way if possible. Thanks.

mskip
Hard to tell w/o seeing your sheet layout, but this will give you the last used row and set the sum and criteria ranges accordingly - merge this with the rest of your code.
Code:
Dim Wb As Workbook, ws As Worksheet
Dim lR As Long
Set Wb = Workbooks("S_DATA.xlsx")
Set ws = Wb.Sheets("OBL")
With Wb.ws
    lR = .UsedRange.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Set oblRangePLL1 = .Range("A2:A" & lR)
    'set other ranges similarly
    .Range("H26").Value = WorksheetFunction.SumIfs(oblRangeMNAmt1, oblRangePLL1, "0968A1", oblRangeLO1, "15", oblRangeFP1, "QSQ0P00Y11")
End With
 
Upvote 0

Forum statistics

Threads
1,216,313
Messages
6,130,011
Members
449,550
Latest member
8073662045

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