Application.WorksheetFunction.SumIf and case sensitivity

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
526
Office Version
  1. 2007
Hello everybody.

I've the following operation:

VBA Code:
result = Application.WorksheetFunction.SumIf(Sheets(1).Columns(1), title, Sheets(1).Columns(2))

The problem is the variable
VBA Code:
title
the variable in the macro is in small letters, but in the criteria column is written in capital letters.

I think this should be the reason for the sum failure (result always 0).

How can I figure it out?

Thank's in advance.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hello everybody.

I've the following operation:

VBA Code:
result = Application.WorksheetFunction.SumIf(Sheets(1).Columns(1), title, Sheets(1).Columns(2))

The problem is the variable
VBA Code:
title
the variable in the macro is in small letters, but in the criteria column is written in capital letters.

I think this should be the reason for the sum failure (result always 0).

How can I figure it out?

Thank's in advance.
"Title" is a reserved word (already been used for something else in VBA). Reserved words are things like names of built-in functions, properties, objects, etc.
One easy well to tell is to create a simple macro where you use it, all entered in lower case, like this:
VBA Code:
Sub Test()
    MsgBox title
End Sub
If Excel automatically capitalizes the first letter, like this:
VBA Code:
Sub Test()
    MsgBox Title
End Sub
that usually indicates that it is a reserved word that in VBA.

You should NEVER use reserved words as the names of your variables, procedures, or functions in VBA. Doing so can cause errors and unexpected results.
Try changing your variable name to something like "myTitle".
 
Upvote 0
Solution

Forum statistics

Threads
1,215,523
Messages
6,125,317
Members
449,218
Latest member
Excel Master

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