나는 ca의 엑셀 시트 내에서 행 수의 연속 수의 최소 합계를 찾으려고합니다. 10.000 행.
1 200
2 -100
3 -300
4 100
5 100
6 100
이것은 -400과 2 개의 행을 제공해야합니다 (물론 다른 공식에있을 수 있습니다).
1 0
2 100
3 -100
4 -100
5 -100
6 100
7 -100
8 100
이것은 -300 및 3 행 등을 제공해야합니다.
감사!
어레이를 사용하여이 프로세스는 10,000 개의 라인에서 3-4 초가 소요되었습니다.
Sub minarr()
Dim i&, j&
Dim rngArr() As Variant
Dim sum As Double
Dim frstrw As Long
Dim lstrw As Long
Dim lastrow As Long
Dim ws As Worksheet
Dim Minout As Double
Set ws = Sheets("Sheet28") 'Change to your sheet
'Change column A to the column of your numbers in the next two lines.
lastrow = ws.Range("A" & ws.Rows.Count).End(xlUp).row
rngArr = ws.Range("A1:A" & lastrow).Value
For i = 1 To lastrow
sum = rngArr(i, 1)
For j = i + 1 To lastrow
sum = sum + rngArr(j, 1)
If sum < Minout Then
Minout = sum
frstrw = i
lstrw = j
End If
Next j
Next i
Debug.Print Minout
Debug.Print frstrw
Debug.Print lstrw
End Sub
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다