View Single Post
 
Old 08-30-2020, 06:23 PM
leeqiang leeqiang is offline Windows 10 Office 2019
Advanced Beginner
 
Join Date: Aug 2020
Posts: 53
leeqiang is on a distinguished road
Default

Quote:
Originally Posted by p45cal View Post
I was asking if the 3 for the group interval was always 3 or if it needed to be calculated from the source data or from perhaps a cell value in the sheet. As it is I've used a hard-coded 3.

In my code, both the starting value and the group pitch are manually entered. Specifically, enter the group spacing in cell B8, and enter the starting data value in cell C1. A judgment condition is also set. When cells C1 and C2 have data and cell B8 has no input data, the group distance can be obtained by subtracting the value of cell C1 from the value of cell C2. Then automatically generate all the separation points of the data, and then other data.

These logics are reflected in my following code:
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