Quote:
Originally Posted by Purfleet
Leeqiang
This is why you need to ask the full question at the begining - in your orginal post you said the 15th row and Column K, so i assumed the grid was static.
If you want to work out varible rows and columns try this - there might be neater or nicer ways but you dont need a loop to sum
Sub sumtheall()
Dim LR As Integer
Dim LC As Variant
Dim LRSum As Integer
Dim LCSum As Variant
'Find last row
LR = Cells(Rows.Count, 1).End(xlUp).Row + 1
LRSum = LR - 1
'Find last column
LC = Cells(1, Columns.Count).End(xlToLeft).Column + 1
'Change column to Letter
LCSum = Chr(LC + 64 - 1)
LC = Chr(LC + 64)
'Input Sum
Range("a" & LR & ":" & LC & LR) = "=sum(a1:a" & LRSum & ")"
Range(LC & "1:" & LC & LR) = "=Sum(a1:" & LCSum & "1)"
End Sub
|
Thank you very much for your help!
run the code have same wrong results in the photo as follows:
20201008111050.png
1.the result don't sum the columns of price, quantity,freight
2.when click the button many times,the result produce under the result before.
I want to produce the result under the data range whatever how many times clicked the button.
3.advanced,how to use the code to get rid of each worksheets's name like *m in this workbook
thx again!