i have in A column some names and in b column some numbers like:
jimmy 4
jimmy 4
carl 8
john 8
I need to sum jimmy's numbers. I mean, if there are some same values in A colum the sum the B numbers of that name. So jimmy = 8. How can i do it? I'm very new in vba so the easy things for me are not so easy :)
EDIT, the macro:
Sub Sample()
Dim path As String
Dim openWb As Workbook
Dim openWs As Worksheet
Dim DataInizio As String
Dim DataFine As String
path = "C:\Me\Desktop\example.xls"
Set thiswb = ThisWorkbook
Set openWb = Workbooks.Open(path)
Set openWs = openWb.Sheets("details")
Set Logore = thiswb.Sheets("Log")
With openWs
start = CDate(InputBox("start (gg/mm/aaaa)"))
end = CDate(InputBox("end (gg/mm/aaaa)"))
Sheets("details").Select
LR = Cells(Rows.Count, "A").End(xlUp).Row
dRow = 2
For r = 2 To LR
If Cells(r, 1) >= start And Cells(r, 1) <= end Then
' Do un nome alle colonne nel file di log indicandone la posizione
ore = Range("K" & r)
nome = Range("J" & r)
totore = totore + ore
If ore <> 8 Then
Range("A" & r & ",J" & r & ",D" & r & ",K" & r).Copy Logore.Cells(dRow, 1)
rigatot = dRow
dRow = dRow + 1
End If
If nome <> Range("J" & r + 1) Then
If totore <> 40 Then
Logore.Cells(dRow, 5) = totore
End If
totore = 0
End If
End If
Next
thiswb.Sheets("Log").Activate
End With
openWb.Close (False)
End Sub
Well, this macro will sum up the values and reprint them as a new list. You can specify the columns as String parameters in your Main sub.
CollectArray "A", "D"
- collects array from columnA
and removes duplicates from it and then prints it to columnD
DoSum "D", "E", "A", "B"
- summs up all values for columnD
and writes them to columnE
- gets the match from columnA
& values from columnB
before:
after: