title: VBA- Sum values in Column B if name in column A is the same
body: <p>I try to edit macro  for summing values in column B, But  it doesnt work correctly: </p>
  
  <p>Here is, what i have:</p>
  
  <pre><code>Option Explicit
  
  Sub Main()
  
      CollectArray "A", "D"
  
      DoSum "D", "E", "A", "B"
  
  End Sub
  
  
  ' collect array from a specific column and print it to a new one without duplicates
  ' params:
  '           fromColumn - this is the column you need to remove duplicates from
  '           toColumn - this will reprint the array without the duplicates
  Sub CollectArray(fromColumn As String, toColumn As String)
  
      ReDim arr(0) As String
  
      Dim i As Long
      For i = 1 To Range(fromColumn &amp; Rows.Count).End(xlUp).Row
          arr(UBound(arr)) = Range(fromColumn &amp; i)
          ReDim Preserve arr(UBound(arr) + 1)
      Next i
      ReDim Preserve arr(UBound(arr) - 1)
      RemoveDuplicate arr
      Range(toColumn &amp; "1:" &amp; toColumn &amp; Range(toColumn &amp; Rows.Count).End(xlUp).Row).ClearContents
      For i = LBound(arr) To UBound(arr)
          Range(toColumn &amp; i + 1) = arr(i)
      Next i
  End Sub
  
  
  ' sums up values from one column against the other column
  ' params:
  '           fromColumn - this is the column with string to match against
  '           toColumn - this is where the SUM will be printed to
  '           originalColumn - this is the original column including duplicate
  '           valueColumn - this is the column with the values to sum
  Private Sub DoSum(fromColumn As String, toColumn As String, originalColumn As String, valueColumn As String)
      Range(toColumn &amp; "1:" &amp; toColumn &amp; Range(toColumn &amp; Rows.Count).End(xlUp).Row).ClearContents
      Dim i As Long
      For i = 1 To Range(fromColumn &amp; Rows.Count).End(xlUp).Row
          Range(toColumn &amp; i) = WorksheetFunction.SumIf(Range(originalColumn &amp; ":" &amp; originalColumn), Range(fromColumn &amp; i), Range(valueColumn &amp; ":" &amp; valueColumn))
      Next i
  End Sub
  
  
  Private Sub RemoveDuplicate(ByRef StringArray() As String)
      Dim lowBound$, UpBound&amp;, A&amp;, B&amp;, cur&amp;, tempArray() As String
      If (Not StringArray) = True Then Exit Sub
      lowBound = LBound(StringArray): UpBound = UBound(StringArray)
      ReDim tempArray(lowBound To UpBound)
      cur = lowBound: tempArray(cur) = StringArray(lowBound)
      For A = lowBound + 1 To UpBound
          For B = lowBound To cur
              If LenB(tempArray(B)) = LenB(StringArray(A)) Then
                  If InStrB(1, StringArray(A), tempArray(B), vbBinaryCompare) = 1 Then Exit For
              End If
          Next B
          If B &gt; cur Then cur = B
          tempArray(cur) = StringArray(A)
      Next A
      ReDim Preserve tempArray(lowBound To cur): StringArray = tempArray
  End Sub
  </code></pre>
  
  <p>Macro will copy names from column A (removes duplicates) to column D, and values from Column B should sum according to names from A column
  Part RemoveDuplicates doesnt work properly. Can someone tell me/help me, where can be problem ? </p>