jeudi 29 mars 2018

I am trying to sum the columns of specific headers in a particular row but I am getting total sum of all columns of that row irrespective of header

'I am trying to sum the columns of specific headers in a particular row but I am getting total sum of all columns of that row irrespective of header. Can someone please tell me my mistake?Please see the attached image for sample input output.enter image description here

Dim DSum As Integer
Dim PSum As Integer
With wsn
    NIMsLastRow = Worksheets("NIMSCarrierCount").Cells(Rows.Count, 1).End(xlUp).Row
    NIMsLastCol = Worksheets("NIMSCarrierCount").Cells(1, Columns.Count).End(xlToLeft).Column
    For j = 2 To NIMsLastRow
        DSum = 0
        PSum = 0
        For k = 2 To NIMsLastCol
            If .Cells(1, k).Value = "LTE 1900Deployed" Or "LTE 2500Deployed" Or "LTE 800Deployed" Or "UnassignedDeployed" Then
                DSum = DSum + CInt(.Cells(j, k).Value)
            End If
            If .Cells(1, k).Value = "LTE 1900Planning" Or "LTE 2500Planning" Or "LTE 800Deployed" Or "UnassignedPlanning" Then
                PSum = PSum + CInt(.Cells(j, k).Value)
            End If
        Next k
        .Cells(j, NIMsLastCol + 1).Value = DSum
        .Cells(j, NIMsLastCol + 2).Value = PSum
    Next j
End With

Aucun commentaire:

Enregistrer un commentaire