判斷及加總
判斷數量計算表加總的邊界是最困難的……因為迴圈是由上而下,而每個邊界條件都一樣,所以需要設定兩個變數,以兩個迴圈來抓取邊界,第二個邊界採用Exit For來增加執行效率。
.FormulaR1C1是相對位置,跑出來的加總沒有$$,未來插入行列才不會跑掉
141For s1 = 6 To r2 If Cells(s1, 4).Value = "Σ=" And Cells(s1, 1).Value <> "" Then3 s2 = s14 For s3 = s2 + 1 To r5 If Cells(s3, 1).Value <> "" Then6 Range(Cells(s2, 5), Cells(s2, 5)).Select7 With Selection8 .FormulaR1C1 = "=sum(R[1]C[]:R[" & s3 - s2 - 1 & "]C[0])"9 End With10 Exit For11 End If12 Next13 End If14Next
沒有留言:
張貼留言