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
Solved

defining and comparing the value of a cell in VB

Posted on 2012-03-12
1
147 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
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

790 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