Для каждой «фермы» в столбце А;Суммируйте значения из столбца C (Количество) для «apple-1» и «apple-2» в столбце B.
Цикл поиска и добавления.Нет ошибокМатематика происходит от неправильных клеток.
Данные
Таблица данных
Sub find_2()
Dim apple_1 As Long, apple_2 As Long
Dim j As Integer
Dim total_aps As Long
Dim name As Range
Dim myrange As Range
last_row = ActiveSheet.Range("A" & Rows.count).End(xlUp).Row
Set myrange = Range("A2:A17" & last_row)
Sheets("Sheet1").Activate
With ActiveSheet
For j = 16 To last_row
For Each name In myrange
If .Cells(j, 2).Value = ("apple-1") Then
apple_1 = Sheet1.Cells(j, 3).Value
End If
If .Cells(j, 2).Value = ("apple-2") Then
apple_2 = Sheet1.Cells(j, 3).Value
End If
total_aps = apple_1 + apple_2
.Cells(j, 6).Value = total_aps
Next
Next j
End With
End Sub
=======================================================================
Expected/Wanted results
Farm Total Count
farm-01 300
farm-02 30
farm-03 3
farm-04 3000
Фактические результаты (см. Общее количество) Фактические результаты