VBA具有多个条件

时间:2017-07-28 06:57:49

标签: vba

我需要一些帮助来修改我的代码,以便在J列中获得正确的值 我为了更好的理解而着色,我从A to D列中获得相同值的行 在专栏J中,我希望获得正确的值,如下所示:
  - 如果row 6 = row 7J6 = 2   - 如果row 8 = row 9 = row 10J8 = 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

enter image description here

0 个答案:

没有答案