View Single Post
 
Old 08-29-2020, 05:28 AM
leeqiang leeqiang is offline Windows 10 Office 2019
Advanced Beginner
 
Join Date: Aug 2020
Posts: 53
leeqiang is on a distinguished road
Default

Use codes to find the maximum, minimum and range in the data. Then manually enter the starting number and group distance of the data split point according to the actual situation. The code code is used to automatically generate the grouping interval, and the last data separation point is the first time the accumulated value is equal to or greater than the maximum value of the data source under the previous grouping logic. The grouping ends.

my code as following:
p = ActiveSheet.Cells.Rows.Count
q = ActiveSheet.Cells(p, 3).End(xlUp).Row
If q >= 2 Then
groupsp = Cells(q, 3) - Cells(q - 1, 3)
[b8] = groupsp
Else
groupsp = [b8].Value
End If
'Range("c3:C" & q).Clear
If q <= 1 And [b8].Value = "" Then Exit Sub
If [c1].Value = "" And [b8].Value <> "" Then Exit Sub
For drow = q + 1 To ActiveSheet.Cells.Rows.Count
Cells(drow, 3) = Cells(drow - 1, 3) + groupsp
If Cells(drow, 3) = vMax Then Exit For
If Cells(drow, 3) > vMax Then Exit For
Next drow

'MsgBox groupsp
[b10] = ActiveSheet.Cells(p, 3).End(xlUp).Row - 1
End Sub
Reply With Quote