1

What I need is really simple. for instance:

        Br         56

        Bc          6

        Bt          20

        Br          23

        bc          15

I want these duplicate bc/br/bt consolidate and sum their numbers This is the part of code I wrote. However it keeps giving me "application-defined or object- defined error". Can anybody tell what is the problem?

         Sub lo()
         Dim sr As Variant
         Range("a1", Range("a1").End(xlDown).End(xlToRight)).Select

           Set sr = Selection

          Range("n1").Consolidate Sources:=sr,
            _Function:=xlSum,TopRow:=False, LeftColumn:=True, 
                _CreateLinks:=False
             End Sub
Nefer Zhang
  • 11
  • 1
  • 7

1 Answers1

0

Apparently this function requires ranges to be in the R1C1 reference style. The below code should work for you.

I also had to move the underscores to the end of each line instead of the beginning of the next line.

         Sub lo()
         Dim sr As Variant
         Range("a1", Range("a1").End(xlDown).End(xlToRight)).Select

           Set sr = Selection

          Range("n1").Consolidate Sources:=sr.address(ReferenceStyle:=xlR1C1), _
            Function:=xlSum,TopRow:=False, LeftColumn:=True, _
                CreateLinks:=False
             End Sub
DiegoAndresJAY
  • 706
  • 4
  • 11