Today is 2014-11-01 is the weekend, busy a week, finally can idle down, think of the recent work to the VBA of a scene, combined with the VBA array, so I want to try, the result is good, come out, this year, and play the VB, after a long time to accept the VB style of grammar, gossip not to say, Go to the Chase
For example, the above data, I now want to figure out how much the sum of QQQ? EE sum is how much, and so on, the data volume is small, you can consider manual statistics, if it is thousands or tens of thousands of data to do, the answer must be VBA. The code for VBA is as follows (because the code is very simple, so do not elaborate, take it to be used):
Sub count_test () Dim i As Integer Dim Arrs () as Variant i = 1 irow = UsedRange.Rows.Count icolumn = Us EdRange.Columns.Count ReDim Preserve arrs (1 to IRow, icolumn-1) for j = 1 to IRow Step 1 strname = Cells (J, 1) Isfind = False k = 0 for k = 1 to IRow If Arrs (k, 0) = strname then isfind = True Exit for< C14/>end if Next k if Isfind then arrs (k, 1) = Arrs (k, 1) + cells (j, 2) Else arrs (i, 0) = Cells (j , 1) Arrs (i, 1) = Cells (j, 2) i = i + 1 End If Next j for k = 1 to IRow If Arrs (k, 0) <&G T "Then cells (k, 4) = Arrs (k, 0) cells (k, 5) = Arrs (k, 1) end If Next k End Sub
after executing this code, the result is:
OK, ready to turn off the computer, go out to play, haha ...
How VBA counts the sum of data of the same type