vba loop script

oframarek

New Member
Joined
Jan 5, 2012
Messages
2
Hi All,
I'm trying to write a vba loop script for a list of numbers.
The scrip should do:

1. Check if the numbers identical.
2. If the numbers identical give a serial number that will count the identical numbers.
3. if The numbers do not match, then start a new series of serial numbers counting.

I have the script for the serial number.
Can you please help me with the script so it will have the conditional part – so the serial number counting will start over when the number in the list changes.

Thanks

Sub counter()
For i = 1 To Cells(Rows.Count, "B").End(xlUp).Row
If Cells(i, "B").Value <> "" Then
Cells(i, "A").Value = i - 0
End If
Next i
End Sub

The final result should look like this (the colores are not needed)
vab_loop-vi.jpg
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Welcome to the MrExcel board!

If you did want a macro, you could try this (not looping though).

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> CreateSerialNumbers()<br>       <SPAN style="color:#00007F">With</SPAN> Range("F2:F" & Range("E" & Rows.Count).End(xlUp).Row)<br>        .Formula = "=IF(E2=E1,F1+1,1)"<br>        .Value = .Value<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br></FONT>
 
Upvote 0

Forum statistics

Threads
1,215,473
Messages
6,125,020
Members
449,203
Latest member
tungnmqn90

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top