Re: [問題] Excel資料整理問題

看板Office作者 (Trade Off)時間16年前 (2008/02/21 13:57), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/3 (看更多)
※ 引述《tea0226 (第1次玩娃娃機夾到戰利品)》之銘言: : (若是和其他不同軟體互動之問題 請記得一併填寫) : 您所使用的軟體為:excel : 版本:2003 : 問題: : 想請問大家一下 : 我有一份資料如下表 : 想要得到連續的負數值跟下一個正值相加的結果 : 例如 B5就是-1-7-9+10=-7 : B9就是-9-7+3=-13 : 因為資料有上百筆 想問是否有簡單的方法得到這些結果 : thanks!! : A B : 1 4 : 2 -1 : 3 -7 : 4 -9 : 5 10 -7 : 6 61 : 7 -9 : 8 -7 : 9 3 -13 請試用這個VBA吧.... __________________________________________________________ Sub test() Dim End_data As Integer End_data = WorksheetFunction.CountA(Range("A:A")) For i = 2 To End_data If Cells(i, 1) > 0 And Cells(i - 1, 1) < 0 Then For j = i - 1 To 1 Step -1 If Cells(j, 1) > 0 Then Exit For Next j Cells(i, 2) = WorksheetFunction.Sum(Range(Cells(i, 1), Cells(j + 1, 1))) Else Cells(i, 2) = "" End If Next i End Sub -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.138.45.37

02/22 15:35, , 1F
thanks! 真的很快...
02/22 15:35, 1F
文章代碼(AID): #17lHBRju (Office)
文章代碼(AID): #17lHBRju (Office)