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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
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,223,786
Messages
6,174,547
Members
452,571
Latest member
MarExcelTips

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