Sum.product with text conditionals

J

Jacek Zagaja

Combobox1 stores unique list of items from data sheet. User clicks on
command button and VB macro prints selected item to the cell. Now with
SUM.PRODUCT I'd like to find selected item in "Item" column and sum
all its values marked KK stored in another column (offset):

=SUM.PRODUCT((Item="selected item")*(Value))

It works nicely but I need to subtract values marked MM that is a
substring of e.g.. 00/11/22/MM/333 II so I added third conditional
(multiplication) that search in KKMM column for MM substring:

TextSearch("MM";KKMM)=True()

It doesn't work so that I'm getting an empty cell. Any ideas?

--
Function TextSearch(ByVal strSearchFor, ByVal Target As Variant) As
Boolean
Dim OneCell As Range

TextSearch = False
If TypeName(Target) = "Range" Then
For Each OneCell In Target
If InStr(1, OneCell.Text, strSearchFor, vbTextCompare) > 0 Then
TextSearch = True
Exit For
End If
Next OneCell
ElseIf TypeName(Target) = "String" Then
If InStr(1, Target, strSearchFor, vbTextCompare) > 0 Then
TextSearch = True
End If

End Function
 
J

Jacek Zagaja

Empty cell appears regardless of "Text Search" routine so it looks
like a major error.

=SUMPRODUCT((ISNUMBER(SEARCH({"MM","mm"}, KKMM)))*Value)
 
S

Shane Devenshire

Hi,

Show us an example of some data and the result you expect. Right now if I
modify your formula to

=SUMPRODUCT(ISNUMBER(SEARCH("mm", G9:G11))*H9:H11)

and H9:H11 contains values and G9:G11 contains 00/11/22/MM/333 II this
formula works. However, {"mm","MM"} will double count!

If this helps, please click the Yes button,

Cheers,
Shane Devenshire
 
J

Jacek Zagaja

Shane,

Could you help me with conditionals?

I'd like to execute <code> if Array2 and Array3 contains specific text
string. In Excel it would be And Array2= {"KK","MM"}. Now placing Or
operator makes Array1 condition untrue.

If a=b And Array1(i) = "text1" And Array2(i) = "KK" Or Array3(i) =
"MM" Then <code>

Regards,
Jack
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top