Home > Software engineering >  Add numbers to rows by block with Excel VBA
Add numbers to rows by block with Excel VBA

Time:10-14

I have data set like this :

City          Money   Code       Quantity
London        1.96    54645641    3         
London        1.96    54645641    3         
London        1.96    54645641    3         
Madrid        200     158484      4         
Madrid        200     158484      4         
Madrid        200     158484      4         
Madrid        200     158484      4          
Denver        56.7    494681818   1  

and i would like to add a number to each line by repeated City's block, i mean to get this :

City          Money   Code       Quantity Number
London        1.96    54645641    3         1
London        1.96    54645641    3         2
London        1.96    54645641    3         3
Madrid        200     158484      4         1
Madrid        200     158484      4         2
Madrid        200     158484      4         3
Madrid        200     158484      4         4
Denver        56.7    494681818   1         1

Some help would be appreciated

CodePudding user response:

Use COUNTIF with a variable range:

=COUNTIF($A$2:A2,A2)

enter image description here

  • Related