Add Multiple Values Based on Criteria

masterton

New Member
Joined
Jul 16, 2014
Messages
14
Add Multiple Values Based on Criteria

Search for the word "Clear" in the Task column.
If the word "Clear" is found, go to Value column.
Add all values starting from "Clear" down to the end of the list.
If it is larger than 10, return the word "OK". Otherwise "Poor".
If 20, return the word "Good".
The length of the list is variable.

Here is the sample worksheet (Please click).

How should I do?
Thanks a lot. :)
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Add Multiple Values Based on Criteria

Search for the word "Clear" in the Task column.
If the word "Clear" is found, go to Value column.
Add all values starting from "Clear" down to the end of the list.
If it is larger than 10, return the word "OK". Otherwise "Poor".
If 20, return the word "Good".
The length of the list is variable.

Here is the sample worksheet (Please click).

How should I do?
Thanks a lot. :)

Clarification:
Each table is treated separately.
If it is larger than 10, return the word "OK". Otherwise "Poor".
If larger than 20, return the word "Good".
If it couldn't find "Clear", return "No match".
 
Last edited:
Upvote 0
Here you go. This will work with the example you showed me and has enough flexibility to be modified a bit by setting the Dims.

Code:
Option Compare Text 'ignore text case
'--------------------------------
Function ConvertToLetter(iCol As Integer) As String
'*** convert col number to letter ***
   If iCol <= 26 Then
   'columns A-Z
   ConvertToLetter = Chr(iCol + 64)
   Else
   ConvertToLetter = Chr(Int((iCol - 1) / 26) + 64) & Chr(((iCol - 1) Mod 26) + 65)
   End If
End Function
'--------------------------------
Sub clearcheck()
Dim ssheet As String
Dim tablecnts As Integer
Dim tablehead As Integer
Dim inittable As Integer
Dim rpt As String
Dim okcrit As Integer
Dim poorcrit As Integer
Dim goodcrit As Integer
Dim result As String
ssheet = "Sheet1" ' actual name of source sheet
tablecnts = 4 'number of tables to process
tablehead = 3 'header row of tables
inittable = 1 'first table's column number
okcrit = 10 'returns OK if value > okcrit
poorcrit = 10 'returns POOR if value < poorcrit
goodcrit = 20 'returns GOOD if value => goodcrit
'***will assume 1 blank column between tables
lastrow = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
For x = 1 To tablecnts
taskrng = ConvertToLetter(Val(inittable)) & "1:" & ConvertToLetter(Val(inittable)) & lastrow
If IsNumeric(Application.Match("Clear", Worksheets(ssheet).Range(taskrng), 0)) Then
hit = Application.Match("Clear", Worksheets(ssheet).Range(taskrng), 0)
valuerng = ConvertToLetter(Val(inittable + 1)) & hit & ":" & ConvertToLetter(Val(inittable + 1)) & lastrow
sumit = WorksheetFunction.Sum(Worksheets(ssheet).Range(valuerng))
'set result
If sumit > okcrit Then
result = "OK"
End If
If sumit >= goodcrit Then
result = "GOOD"
End If
If sumit < poorcrit Then
result = "POOR"
End If
rpt = rpt & vbCr & Worksheets(ssheet).Cells(tablehead, inittable) & "=" & sumit & " [" & result & "]"
Else
rpt = rpt & vbCr & Worksheets(ssheet).Cells(tablehead, inittable) & "=" & "NO MATCH" & " [N/A]"
End If
inittable = inittable + 3
Next x
MsgBox rpt
End Sub
 
Upvote 0
Try...

=IF(COUNTIF(TaskRange,"Clear"),LOOKUP(SUMIF(TaskRange,"Clear",ValueRange),{0,10,20},{"Poor","OK","Good"}),"No Match")

Clarification:
Each table is treated separately.
If it is larger than 10, return the word "OK". Otherwise "Poor".
If larger than 20, return the word "Good".
If it couldn't find "Clear", return "No match".
 
Upvote 0

Forum statistics

Threads
1,216,079
Messages
6,128,687
Members
449,464
Latest member
againofsoul

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top