VBA Excel sumif how to inclued a not equal criteria

Posted on 2010-09-02
Medium Priority
Last Modified: 2012-05-10
I'm running some VBA code that passes to a sumif formula a string criteria I want that string criteria to be a not equal to stsement please see below, at the moment it adds everyting rather than excluding the search criteria

searchview= "<>CVN"

.SumIf(grnlable, SearchView, Range("tblCalc[Renewal_Premium]"))
Question by:Thrawn3000
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 58

Expert Comment

ID: 33592880
Is CVN the text "CVN"?
Try this

searchview= "<>""CVN"""
LVL 58

Accepted Solution

cyberkiwi earned 2000 total points
ID: 33592892
You can ignore the previous comment.
Now that I have had a chance to test it, this works fine for me (Excel 2010)

searchview = "<>CVN"
MsgBox WorksheetFunction.SumIf(Range("A1:A10"), searchview, Range("B1:B10"))

Is the text CVN exactly or does it have extra spaces after?

Author Comment

ID: 33592904
there are no extra spaces it is exactly CVN
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

LVL 46

Expert Comment

ID: 33592907
searchview = "<>'CVN'"

Author Comment

ID: 33592939
No luck with that
LVL 58

Expert Comment

ID: 33593405
I think the key was to re-evaluate whether the text was in fact "CVN" exactly.
I was also of the mind like aikimark that quotes were required, but not so from VBA/worksheetfunction.

Author Closing Comment

ID: 33614252
The syntax this solution perscribed is correct.

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Make the most of your online learning experience.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question