excel - Sum of a column -
i want calculate sum of different columns in worksheet , fill in worksheet.
lastrowa = weight.cells(weight.rows.count, "a").end(xlup).row set rng = weight.range("a2" & lastrowa) weight.activate summ= worksheetfunction.sum(rng) ' doesn't work summary.cells(1, 1).value=summ summary.cells(1, 1).value = application.sum(rng) ' doesn't work the 2 sheets weight , summary. have tried above 2 ways , both give me answer of zero. want continue doing columns . please advice. thank you.
this sub sum data in sheet 1 columns c , put results in sheet2
you can use sub , change column letters , output cells.
hope helps
sub sumrange() dim wb workbook set wb = thisworkbook dim ws worksheet set weight = wb.sheets("weight") lastrow1 = weight.range("a" & rows.count).end(xlup).row set rng = weight.range("a2:a" & "" & lastrow1 & "") col1sum = worksheetfunction.sum(rng) lastrow1 = weight.range("b" & rows.count).end(xlup).row set rng = weight.range("b2:b" & "" & lastrow1 & "") col2sum = worksheetfunction.sum(rng) lastrow1 = weight.range("c" & rows.count).end(xlup).row set rng = weight.range("c2:c" & "" & lastrow1 & "") col3sum = worksheetfunction.sum(rng) thisworkbook.sheets("sheet2").cells(2, 2).value = col1sum thisworkbook.sheets("sheet2").cells(3, 2).value = col2sum thisworkbook.sheets("sheet2").cells(4, 2).value = col3sum end sub
Comments
Post a Comment