TrevorExcel
New Member
- Joined
- Nov 17, 2018
- Messages
- 1
I have a list of foods with the amounts of each food in the left column, the unit of measurement for these foods in the middle and the type of food in the right column. I have been trying to write a VBA code that will cycle through this list and 'tidy it up' for me if their are multiple entries of the same food. By 'tidy it up' I would like the duplicate foods in the list to be added up. Below is a before and after example.
Before:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]250[/TD]
[TD="align: center"]grams[/TD]
[TD="align: center"]carrot[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]tin[/TD]
[TD="align: center"]tomatoes[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]50[/TD]
[TD="align: center"]grams[/TD]
[TD="align: center"]spinach[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]90[/TD]
[TD="align: center"]grams[/TD]
[TD="align: center"]carrot[/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]tin[/TD]
[TD="align: center"]tomatoes[/TD]
[/TR]
[TR]
[TD="align: center"]6[/TD]
[TD="align: center"]0.5[/TD]
[TD="align: center"]bunch[/TD]
[TD="align: center"]basil[/TD]
[/TR]
[TR]
[TD="align: center"]7[/TD]
[TD="align: center"]400[/TD]
[TD="align: center"]grams[/TD]
[TD="align: center"]carrot[/TD]
[/TR]
</tbody>[/TABLE]
After:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]740[/TD]
[TD="align: center"]grams[/TD]
[TD="align: center"]carrrot[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]4[/TD]
[TD="align: center"]tin[/TD]
[TD="align: center"]tomatoes[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]50[/TD]
[TD="align: center"]grams[/TD]
[TD="align: center"]spinach[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]0.5[/TD]
[TD="align: center"]bunch[/TD]
[TD="align: center"]basil[/TD]
[/TR]
</tbody>[/TABLE]
I have been attempting to write a 'For loop' however I have not had much success.
Any help would be appreciated. Thanks in advance
Before:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]250[/TD]
[TD="align: center"]grams[/TD]
[TD="align: center"]carrot[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]tin[/TD]
[TD="align: center"]tomatoes[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]50[/TD]
[TD="align: center"]grams[/TD]
[TD="align: center"]spinach[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]90[/TD]
[TD="align: center"]grams[/TD]
[TD="align: center"]carrot[/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]tin[/TD]
[TD="align: center"]tomatoes[/TD]
[/TR]
[TR]
[TD="align: center"]6[/TD]
[TD="align: center"]0.5[/TD]
[TD="align: center"]bunch[/TD]
[TD="align: center"]basil[/TD]
[/TR]
[TR]
[TD="align: center"]7[/TD]
[TD="align: center"]400[/TD]
[TD="align: center"]grams[/TD]
[TD="align: center"]carrot[/TD]
[/TR]
</tbody>[/TABLE]
After:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]740[/TD]
[TD="align: center"]grams[/TD]
[TD="align: center"]carrrot[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]4[/TD]
[TD="align: center"]tin[/TD]
[TD="align: center"]tomatoes[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]50[/TD]
[TD="align: center"]grams[/TD]
[TD="align: center"]spinach[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]0.5[/TD]
[TD="align: center"]bunch[/TD]
[TD="align: center"]basil[/TD]
[/TR]
</tbody>[/TABLE]
I have been attempting to write a 'For loop' however I have not had much success.
Any help would be appreciated. Thanks in advance