Solved

defining and comparing the value of a cell in VB

Posted on 2012-03-12
1
143 Views
Last Modified: 2012-03-13
I have the following statement in VB;

PROD = Cells(stateRow, 2).Value

I am trying to compare the contents of this cell (which changes relative to the row)
The length of the contents is variable.

I would like to compare the contents of this cell to another cell (PRODX)  on a spreadsheet to use in a sumifs statement in VB.

The challenge is the the value of PRODX can be the value of PROD  & "*"  

Can someone tell me how to code a sumif in VB comparing PROD to PROD X.

This is an example of what I am using when I am matching two fields that are the same length

totYr = Round(Application.WorksheetFunction.SumIfs(Range("pAuths"), _
                              Range("pEvent"), evtType, _
                              Range("pYr"), Pyr, _
                              Range("ProdX"), PROD) / Members, 2)
0
Comment
Question by:morinia
1 Comment
 
LVL 3

Accepted Solution

by:
DaFranker earned 500 total points
Comment Utility
So if I understand correctly, what you want is a function that returns the sum of the values in a range, but only counting values that have a corresponding cell equal to  PROD or PRODX?

If so, why not simply use "If (.value = PROD) Or (.value = PRODX) Then _(...)" to compare?

If instead, what you meant was that you want to compare PROD against PRODX, but also validate if PRODX = PROD & "*" and add that number even if there's an offending asterisk, that's also very simple.

To ignore the ending asterisk, simply add a condition similar to: If (PRODX = PROD) Or (PRODX = PROD & "*") Then _(...)

If VB complains or fails to recognize the second comparison, simply assign a temporary local variable in the function and let it = PROD & "*", and compare PRODX to it.

I'd also take the opportunity to point out that calls to WorksheetFunction methods are much slower than retrieving the values once, doing the comparison in full VBA code, and then setting cell values or returning if you're using a UDF.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now