• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Replace individual values with the sum

Portucale

Member
HI,

Looking to replace all the rows where the value is "1" by the sum of them and for the respective country with a "tech reason" of "OTHER", in the example enclosed we would see:
48 / 4 / UK / Other
48 / 5 / ROI / Other

Thanks in advance,
 

Attachments

  • Chandoo_Countifs.xlsx
    9.5 KB · Views: 6
Assume cells A31:34 values should all be 48?

If there's only one 1 for a given week, should its tech reason be changed to "Other" too?
 
Assuming the answer's Yes to both my queries in the last msg then test this on the active sheet:
Code:
Sub blah()
Set Rng = Range("A1").CurrentRegion
With Rng
  For Each cll In .Columns(2).Cells
    If cll.Value = 1 Then
      If Application.CountIfs(.Columns(2), 1, .Columns(3), cll.Offset(, 1)) > 0 Then
        cll.Offset(, 2).Value = "Other"
        cll.FormulaR1C1 = "=COUNTIFS(R1C1:R34C1,RC[-1],R1C3:R34C3,RC[1],R1C4:R34C4,""Other"")"
      End If
    End If
  Next cll
    .Columns(2).Value = .Columns(2).Value
    .RemoveDuplicates Columns:=Array(1, 2, 3, 4), Header:=xlYes
End With
End Sub
 
Back
Top