我需要一些帮助来修改我的代码,以便在J
列中获得正确的值
我为了更好的理解而着色,我从A to D
列中获得相同值的行
在专栏J
中,我希望获得正确的值,如下所示:
- 如果row 6 = row 7
则J6 = 2
- 如果row 8 = row 9 = row 10
则J8 = 3
- 等等
我的代码不够好,因为我不希望在red values
列中有J
Dim tw As Worksheet: Set tw = ThisWorkbook.Worksheets("stack")
Dim row As Integer
row = tw.Range("B" & Rows.Count).End(xlUp).row
lin = 2
Do Until lin = row + 1
nr = 1
While (tw.Cells(lin, 1) = tw.Cells(lin + nr, 1) And tw.Cells(lin, 2) = tw.Cells(lin + nr, 2) And tw.Cells(lin, 3) = tw.Cells(lin + nr, 3) And tw.Cells(lin, 4) = tw.Cells(lin + nr, 4))
nr = nr + 1
Wend
If nr = 1 Then
Else
tw.Cells(lin, 10) = nr
End If
lin = lin + 1
Loop