Solved

defining and comparing the value of a cell in VB

Posted on 2012-03-12
1
148 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
[X]
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
1 Comment
 
LVL 3

Accepted Solution

by:
DaFranker earned 500 total points
ID: 37712056
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

733 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