conting pork

  • Thread starter Thread starter ksnapp
  • Start date Start date
K

ksnapp

here is the code that i have come up with thus far regarding my ealie
post:

Sub addaTHINGS()

Dim P As Single
Dim N As Double

For Each cell In selection

CASETEXT = cell.Value

Select Case (CASETEXT)

Case Is = "Pork"

P = P + 1

Case Is = "End"
P = P - 1

End Select
Next cell
If P > 1 Then
Do Until P = 0
CASETEXT = cell.Value
Select Case (CASETEXT)
Case Is = "Pork"
P = P - 1
N = N + cell.Offset(0, 1).Value
cell.Offset(-1, 0).Select
Case Is <> "End"
cell.Offset(-1, 0).Select
End Select
Loop
End If
MsgBox (N)
End

It is supposed to go down column selection and give me the sum of por
if there are more than one entries between the end cell.
if there is only one entry for pork than it need not do anything.
in the column to the right of where pork and end live is occupied b
the quanties of vaious things. end also has a value to is right

any help is good help. Im seeing fuzzy
 
Here's a simple example.

Say your pork is in column A
And your amounts are in column B

Use this formula
=IF(COUNTIF(A1:A7,"pork")>1,SUMIF(A1:A7,"pork",B1:B7))
 
Back
Top