VBA SumIfs not working - Expenses management tool in Excel 2007

NadCu42

New Member
Joined
Apr 18, 2016
Messages
1
Hello,
I'm trying to build an expenses management tool in Excel 2007. The main sheet should scan the app directory for another xls_ files and extract my expenses data from them. I wrote this VBA code for the data import:

Code:
Public Function sumMonthExpenseByCategory(ByVal istr_WbFilename As String, _
                                      istr_expenseCategory As String)    ' for example: "Insurance"
    
    Dim str_FileName               As String
    Dim rng_SumRange            As Range
    Dim rng_ConditionRange     As Range
    Dim rng_CurrRange            As Range
    Dim wb_Source                As Workbook
    Dim o_ExcelApplication      As Excel.Application

    Set o_ExcelApplication = New Excel.Application    
    o_ExcelApplication.ScreenUpdating = False

    ' Opening the Source Excel workbook in ReadOnly mode:
    str_FileName = getAppPath & istr_WbFilename

    Set wb_Source = o_ExcelApplication.Workbooks.Open(str_FileName, , True)
    
    If Not wb_Source Is Nothing Then
        Set rng_SumRange = wb_Source.Sheets(1).Range("Sum")
        Set rng_ConditionRange = wb_Source.Sheets(1).Range("Category")
        sumMonthExpenseByCategory = o_ExcelApplication.WorksheetFunction.SumIfs(rng_SumRange, rng_ConditionRange, istr_expenseCategory)     ' Should be: 163.25

    ' Closing the source workbook:
    wb_Source.Close False             ' Not saving the file when closing it
    Set wb_Source = Nothing
    
    End If

This is my expense data from my credit card provider (I'm Israeli, so for this thread I manually translated the values to simple examples in English):
(I'm writing on my PC at work so I cannot download any addins for formatting tables and also I cannot seem to paste this table correctly... :()

date expense text Sum currency Category
22/12/2015 restaurant #1 42 ₪ Lunch at work
23/12/2015 restaurant #2 42 ₪ Lunch at work
24/12/2015 restaurant #3 58 ₪ Lunch at work
27/12/2015 restaurant #4 38 ₪ Lunch at work
28/12/2015 restaurant #5 50 ₪ Lunch at work
29/12/2015 restaurant #6 38 ₪ Lunch at work
30/12/2015 restaurant #7 40 ₪ Lunch at work
31/12/2015 restaurant #8 46 ₪ Lunch at work
12/11/2015 life insurance 101.5 ₪ Insurance
28/12/2015 health insurance 61.75 ₪ Insurance
14/12/2015 gas for car 187.7 ₪ Gas
27/12/2015 gas for car 196.35 ₪ Gas
15/12/2015 parking near home 22 ₪ Parking
16/12/2015 parking near work 6 ₪ Parking
27/12/2015 parking near mall 33 ₪ Parking
30/12/2015 parking at girlfriend's 55 ₪ Parking
01/03/2016 Tel Aviv muni 557.41 ₪ City bill
30/12/2015 Electra Ways inc. 644.63 ₪ Electricity bill
30/12/2015 Spring Water inc. 71.1 ₪ Water bill
30/12/2015 Haaretz magazine ltd 196 ₪ Newspaper

I'm succeeding in opening the file and I get the data ranges, but the SUMIFS function always return 0.
Can anyone figure out why is that so?

Thank you very much!
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,216,057
Messages
6,128,520
Members
449,456
Latest member
SammMcCandless

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