Jun 16 2022 08:00 AM
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 in column C that correspond to the matching dates in column A. The end result is column D which displays the number of apples in that day total. The highlighted portions are matching days. I have included a picture of this excel
Jun 16 2022 08:33 AM
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 Sub
Maybe with these lines of code. In the attached file you can click the button in cell E2 to start the macro.
Jun 16 2022 09:08 AM
Jun 16 2022 09:50 AM
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 Sub
Maybe with this code. In the attached file you can click the button in cell F2 to start the macro.