Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
462 views
in Technique[技术] by (71.8m points)

excel - Increment value in cell according another value in another cell

I need do something in VBA but i don't know anything in it..

I don't find any code on the web doing what i need...

I've think this explain much what i need (this not work):

         Column A                  Column B
Rows 1 | N°                        | REFERENCE EXP
Rows 2 | 1                         | 305-871
Rows 3 | =if(B3<>B2;A3=A2+1;A3=A2) | 402-920
Rows 4 | =if(B4<>B3;A4=A3+1;A4=A3) | 402-920
Rows 5 | =if(B5<>B4;A5=A4+1;A5=A4) | 406-585

So, the result do something like that :

         Column A                  Column B
Rows 1 | N°                        | REFERENCE EXP
Rows 2 | 1                         | 305-871
Rows 3 | 2                         | 402-920
Rows 4 | 2                         | 402-920
Rows 5 | 3                         | 406-585
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I've find how to increment but the increment dosn't stop...

My code:

Set derlign = Range("B" & Rows.count).End(xlUp)
'MsgBox ("Dernière ligne " & derlign & " !")
Set r1 = Range("A2:A100")
Set r2 = Range("B2:B100")
For N = 2 To r2.Rows.count
    If r2.Cells(N - 1, 1) = r2.Cells(N, 1) Then
       r1.Cells(N, 1) = r1.Cells(N - 1, 1)
    Else
       r1.Cells(N, 1) = r1.Cells(N - 1, 1) + 1
    End If
Next N
End Sub`

(my next post where i ask how to stop the increment)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...