montecarlo2012
Well-known Member
- Joined
- Jan 26, 2011
- Messages
- 986
- Office Version
- 2010
- Platform
- Windows
Hello.
This code do not give me any error return; but do not give me the right results either.
I am trying to get the total of oranges sold only, on "C1". My data Fruit's names A, and quantity sold B
and this is the code I tried.
This code do not give me any error return; but do not give me the right results either.
I am trying to get the total of oranges sold only, on "C1". My data Fruit's names A, and quantity sold B
and this is the code I tried.
Code:
Sub Fr_Sd()
Dim LastRow As Long
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
Dim i As Long, Total As Long
For i = 2 To LastRow
If Cells(i, 1).Value = "Oranges" Then
Total = Total + Cells(i, 2).Value
End If
Next i
Range("C1").Value = Total
End Sub
Code:
[TABLE="width: 264"]
<tbody>[TR]
[TD="class: xl63, width: 88"]Fruits[/TD]
[TD="class: xl63, width: 88"]Sold[/TD]
[TD="class: xl64, width: 88"][/TD]
[/TR]
[TR]
[TD="class: xl64"]apples[/TD]
[TD="class: xl63"]8[/TD]
[TD="class: xl63"][/TD]
[/TR]
[TR]
[TD="class: xl64"]bananas[/TD]
[TD="class: xl63"]16[/TD]
[TD="class: xl64"][/TD]
[/TR]
[TR]
[TD="class: xl65"]oranges[/TD]
[TD="class: xl63"]24[/TD]
[TD="class: xl64"][/TD]
[/TR]
[TR]
[TD="class: xl64"]pears[/TD]
[TD="class: xl63"]32[/TD]
[TD="class: xl64"][/TD]
[/TR]
[TR]
[TD="class: xl64"]mangos[/TD]
[TD="class: xl63"]40[/TD]
[TD="class: xl64"][/TD]
[/TR]
[TR]
[TD="class: xl64"]papayas[/TD]
[TD="class: xl63"]48[/TD]
[TD="class: xl64"][/TD]
[/TR]
[TR]
[TD="class: xl64"]mangos[/TD]
[TD="class: xl63"]56[/TD]
[TD="class: xl64"][/TD]
[/TR]
[TR]
[TD="class: xl65"]oranges[/TD]
[TD="class: xl63"]64[/TD]
[TD="class: xl64"][/TD]
[/TR]
[TR]
[TD="class: xl65"]oranges[/TD]
[TD="class: xl63"]72[/TD]
[TD="class: xl64"][/TD]
[/TR]
[TR]
[TD="class: xl64"]apples[/TD]
[TD="class: xl63"]80[/TD]
[TD="class: xl64"][/TD]
[/TR]
[TR]
[TD="class: xl65"]oranges[/TD]
[TD="class: xl63"]88[/TD]
[TD="class: xl64"][/TD]
[/TR]
[TR]
[TD="class: xl64"]bananas[/TD]
[TD="class: xl63"]96[/TD]
[TD="class: xl64"][/TD]
[/TR]
[TR]
[TD="class: xl64"]mangos[/TD]
[TD="class: xl63"]104[/TD]
[TD="class: xl64"][/TD]
[/TR]
[TR]
[TD="class: xl64"]papayas[/TD]
[TD="class: xl63"]112[/TD]
[TD="class: xl64"][/TD]
[/TR]
[TR]
[TD="class: xl64"]mangos[/TD]
[TD="class: xl63"]120[/TD]
[TD="class: xl64"][/TD]
[/TR]
[TR]
[TD="class: xl65"]oranges[/TD]
[TD="class: xl63"]128[/TD]
[TD="class: xl64"][/TD]
[/TR]
[TR]
[TD="class: xl65"]oranges[/TD]
[TD="class: xl63"]136[/TD]
[TD="class: xl64"][/TD]
[/TR]
[TR]
[TD="class: xl64"]apples[/TD]
[TD="class: xl63"]144[/TD]
[TD="class: xl64"][/TD]
[/TR]
[TR]
[TD="class: xl65"]oranges[/TD]
[TD="class: xl63"]152[/TD]
[TD="class: xl64"][/TD]
[/TR]
</tbody>[/TABLE]
Last edited: