Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to sum the column codes in VBA list box
How to sum the column codes in VBA list box
If a column or a row of data is summed, it can be summed by cyclic accumulation. Take a column of sum as an example, the code is as follows:

Include Count ()

DimrowcountAsInteger

Di Jean Makoun Sintegel

rowcount=ActiveSheet。 【a90000】。 End (xlUp). row

Fori= 1Torowcount

A count = A count+Range(" A " & amp; I). value

then

End joint

If you use row sum, take the sum of the first row as an example, the code is as follows.

Include Count ()

DimcolumncountAsInteger

Di Jean Makoun Sintegel

columncount=ActiveSheet。 [IV 1]。 End(xlToLeft)。 column

Fori= 1Tocolumncount

aCount=aCount+Cells( 1,I)。 value

then

End joint

If the sum is irregular, you can first store the data in the array and realize the sum in the slave array. Taking cells A 1, B2 and C3 as examples, the coding is as follows:

Include Count ()

DimarrData(2)

Di Jean Makoun Sintegel

Fori = bidirectional (arrData)

Arr data(I)= cell (i+ 1, i+ 1). value

aCount=aCount+arrData(i)

then

EndSub .