Forum Discussion
mousepad1254
Jun 16, 2022Copper Contributor
Excel coding help comparing values and matching data
I am trying to code this excel to help with a work project. The objective is to check if any date in column A matches with another date in that column. If it matches It is supposed to add the numbers...
OliverScheurich
Jun 16, 2022Gold Contributor
Sub apples()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim row1 As Integer
Range("D2:D1000").Clear
k = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To k
If Cells(i, 1).Value = Cells(i + 1, 1).Value Then
j = j + Cells(i, 3).Value
If Cells(i, 1).Value <> Cells(i + 2, 1).Value Then
j = j + Cells(i + 1, 3).Value
Cells(i + 1, 4).Value = j
j = 0
Else
End If
Else
End If
Next i
End SubMaybe with these lines of code. In the attached file you can click the button in cell E2 to start the macro.
mousepad1254
Jun 16, 2022Copper Contributor
Thank you very much that worked. Is there a way to also still display the values that are not the same date in the same column?
- OliverScheurichJun 16, 2022Gold Contributor
Sub apples() Dim i As Integer Dim j As Integer Dim k As Integer Dim row1 As Integer Range("D2:D1000").Clear k = Range("A" & Rows.Count).End(xlUp).Row For i = 2 To k If Cells(i, 1).Value = Cells(i + 1, 1).Value Then j = j + Cells(i, 3).Value If Cells(i, 1).Value <> Cells(i + 2, 1).Value Then j = j + Cells(i + 1, 3).Value Cells(i + 1, 4).Value = j j = 0 Else End If Else If Cells(i + 1, 1).Value <> Cells(i + 2, 1).Value Then Cells(i + 1, 4).Value = Cells(i + 1, 3).Value Else End If End If Next i End SubMaybe with this code. In the attached file you can click the button in cell F2 to start the macro.