How to count two different column?

-1

I really need your help regarding the below table, I need a formula to show me how many pending/closed for each project.

Project Status                      Project    Pending  Closed
VIVA    closed                      VIVA         1       2
ZAIN    closed                      ZAIN         1       1
VIVA    PENDING                     WATANIA      1       0
WATANIA closed              
ZAIN    PENDING             
VIVA    closed      

Ahmed

Posted 2014-06-07T13:41:31.803

Reputation: 1

3Make sure you use proper formatting when asking questions, very hard to read otherwise. Also, what exactly do you want from this? You have multiple projects with the same name according to your data. Eg; VIVA appears 3 times, twice is labelled as closed, once its labelled as PENDING – Jonny Wright – 2014-06-07T13:49:42.487

Answers

0

I only know VBa (I don't really know workbook functions) so since you don't specify which you want, this VBa should do what you want

Sub UpdateStatus()

Dim row As Integer
row = 2 ' sets the starting row    

Dim statisticRow As Integer
statisticRow = 2

Do While (True) ' we must reset everything before we go on our quest. Be gone foul witch

If Range("F" & statisticRow).Value = "" Then
Exit Do
End If

Range("F" & statisticRow).Value = ""
Range("G" & statisticRow).Value = ""
Range("H" & statisticRow).Value = ""
statisticRow = statisticRow + 1
Loop

Do While (True)

Dim currentValue As String
currentValue = Range("A" & row).Value

Dim otherValue As String

    If currentValue = "" Then
        Exit Do
    End If

Dim otherRow As Integer
otherRow = 2 ' sets the starting row where the results are


Do While (True) ' find it or add it        

    otherValue = Range("F" & otherRow).Value
    Dim currentValueStatus As String
    If otherValue = "" Then             

        currentValueStatus = Range("B" & row).Value

        Range("F" & otherRow).Value = currentValue

         If currentValueStatus = "closed" Then
            Range("H" & otherRow).Value = 1
        End If

        If currentValueStatus = "PENDING" Then
            Range("G" & otherRow).Value = 1
        End If

        Exit Do
    End If

    If currentValue = otherValue Then ' Good news sire, I found it

        currentValueStatus = Range("B" & row).Value

        If currentValueStatus = "closed" Then
            Range("H" & otherRow).Value = Range("H" & otherRow).Value + 1
        End If

        If currentValueStatus = "PENDING" Then
            Range("G" & otherRow).Value = Range("G" & otherRow).Value + 1
        End If

    Exit Do

    End If
    otherRow = otherRow + 1
    Loop
    row = row + 1

Loop    

End Sub

Before

enter image description here

And after I run the macro

enter image description here

As you can see, it will automatically put in the company names for you, and work out how many of each exist. This means, if you added a new company and ran the macro again, it will be updated with the new detail without any change to the code.

Dave

Posted 2014-06-07T13:41:31.803

Reputation: 24 199