Summarising Data using VBA

sam987

New Member
Joined
Dec 20, 2017
Messages
1
animalsExcel.PNG

https://imgur.com/sD0lKf3

Hi Everyone,

I'm fairly new to VBA and i'm trying to achieve the above task. Basically i want to sort through the data such that the animals are summed to provide a total sum of a particular type of animal under a designated letter as shown. also, I only want to display the animal type if its sum is greater than zero, as shown in letters B and C summary.

I have very basic code at this point which will eventually be used to systematically sort through the data by comparing if the letter has changed from the last cell, and if it has, print the relevant information, using the SumArray variable and a range offset.

'calculate count of columns
ColCount = Range("b2", Range("b2").End(xlToRight)).Count

'calculate count of rows
RowCount = Range("a4", Range("a3").End(xlDown)).Count

ReDim SumArray(1 To 9, 1 To 1)

For i = 1 To ColCount
Array1 = Range(Range("b4").Offset(0, i - 1), Range("b4").Offset(RowCount - 1, i - 1))


For j = 1 To UBound(Array1)
SumArray(j, 1) = Array1(j, 1) + SumArray(j, 1)
Next j

Next i

I want to know if this would be the best way to go about it, because even at this point I feel as though there is a lot of reading and writing to different points involved. I also want the code to be adaptable to include additional rows/columns etc.

Thanks
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
sam987,

Welcome to the MrExcel forum.

You are posting a picture. This means that if this was a problem where one needed to use your data, anyone trying to help you would have to enter the data manually.

Can we see what your actual raw data workbook/worksheets look like, and, can we see what the results (manually formatted by you) should look like?

You can post your workbook/worksheets to the following free site (sensitive data changed), mark the workbook for sharing, and, provide us with a link to your workbook:

https://dropbox.com
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,249
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top