Solved

VBA Excel sumif how to inclued a not equal criteria

Posted on 2010-09-02
9
1,075 Views
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]"))
0
Comment
Question by:Thrawn3000
  • 3
  • 3
9 Comments
 
LVL 58

Expert Comment

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

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

Accepted Solution

by:
cyberkiwi earned 500 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?
0
 

Author Comment

by:Thrawn3000
ID: 33592904
Cyberkiwi
there are no extra spaces it is exactly CVN
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 45

Expert Comment

by:aikimark
ID: 33592907
searchview = "<>'CVN'"
0
 

Author Comment

by:Thrawn3000
ID: 33592939
No luck with that
0
 
LVL 58

Expert Comment

by:cyberkiwi
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.
0
 

Author Closing Comment

by:Thrawn3000
ID: 33614252
The syntax this solution perscribed is correct.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

680 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