automaticaly assigning numbers to rows

Adz

New Member
Joined
Jun 18, 2011
Messages
16
Hi all,
This is probably a very easy question for the guru's here.

What i am trying to do is allocate a consecutive number to each row in a cell at the end of each row. this in itself is easy. The problem I have is if i need to delete or insert a row I need the consecutive numbers to change accordingly.

to give an idea of the layout, the rows are competition entries in various categories. some entries pull out and there are constantly entries being added to categories. The idea is that at the cutoff date entries will all have a unique entry number and we will have a total count of entries ( the total count is easy its just the changing unique number)

I hope i explained myself properly and I thank anyone who can help in advance

Cheers
 
ok.. turned off the stupid in my head lol.. cheers michael and everyone who helped, works perfect
 
Last edited:
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
I changed your script to make it do it the way I wanted it. works perfect cheers.
I do however have one more question, I need to do the same thing in the Judging score column(H) but it need to have conditions from column B

Unsure if I can explain myself properly but here goes..
column B has the category I.E. 1.1,1.2,2.1 etc.
I need column H to count the same value, skip blank cells then start count again when a new value is detected. and be able to remove and insert rows as with the other script.( both need to be running)

Excel Workbook
ABCDEFGHIJ
946662.1Saddlers Creek WinesReserveRiesling20102991
956822.1St Hallett WinesEden ValleyRiesling20103092
96
973382.2Ballast Stone EstateCurrency CreekWater RibbonGewrztraminer2010193
983022.2Ernest HillMaisie EvelynGewrztraminer2011294
992.2G. Patritti & Co Pty LtdPatrittiBlewitt Springs EstateGewrztraminer2008395
100
101842.3Burk Salter WinesBurk SalterMuscat Gordo Blanco2009196
1022.3De Bortoli WinesSacred HillTraminer/ Riesling2010297
1031192.3Heafod GlenLoose GooseViognier/ Chenin/ Verdelho2011398
1042212.3Jacob's Creek WinesMoscato WhiteGordo/ Orange Muscat/ White Frontignac2010499
105
1065643.1Australian Vintage LTDNepentheChardonnay20101100
1076773.1Blue Pyrenees EstateLeydens ValeChardonnay20082101
entries proofread
Excel 2007


I'm sure I probably just need to use same script with a couple of bits added but this is fairly new to me and am having trouble working it out.
 
Upvote 0
Sorry Adz...had to go and play golf.....that was a waste of time !!!
If I understand you correctly, try
Code:
Sub adder2()
Dim lr As Long, r As Long
lr = Cells(Rows.Count, "B").End(xlUp).Row
s = 1
For r = 1 To lr
    If Range("B" & r).Value <> "" Then Range("H" & r).Value = s
    s = s + 1
    If Range("B" & r).Value = "" Then s = 1
Next r
End Sub
 
Upvote 0
Hi Michael,
Bad luck with the golf mate.

The code you gave nearly does it just 2 little things.
1 It starts 1 in the heading row instead of row 2, the rest of the gaps in data are perfect.
2 when I delete a row it doesnt re adjust count (33,34,35 becomes 33,35)

Thanks heaps for all your help.
 
Upvote 0
Ok, a couple of changes
Code:
for r = 1
needs to be For r =2
and it needs to be a Worksheet change event

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim lr As Long, r As Long
lr = Cells(Rows.Count, "B").End(xlUp).Row
s = 1
For r = 2 To lr
    If Range("B" & r).Value <> "" Then Range("H" & r).Value = s
    s = s + 1
    If Range("B" & r).Value = "" Then s = 1
Next r
End Sub
 
Upvote 0
Ok,
starting number fixed ( I stared at that code for ages trying to work out which part indicated starting cell lol)
still dropping number when row deleted.

and your knowledge has inspired me to brush the dust off my VB for excel book i've had for years and never read and also to read every one of the 2.5 million posts on this forum lol.
 
Upvote 0
also, not sure if it matters, it's in with code for other count as well

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set Rng = Range(Cells(2, 10), Cells(Rows.Count, 10).End(xlUp)(2, 1))
Rng.Formula = "=IF(NOT(ISBLANK(B2)),COUNTA(B$2:B2),"""")"

Dim lr As Long, r As Long
lr = Cells(Rows.Count, "B").End(xlUp).Row
s = 1
For r = 2 To lr
If Range("B" & r).Value <> "" Then Range("H" & r).Value = s
s = s + 1
If Range("B" & r).Value = "" Then s = 1
Next r
End Sub
 
Upvote 0
sorry for all the posts.
Ignore everything I just said... works perfect. Laptop was having a slow moment. closed and re opened and it's exactly what I need.

Again, many thanks.
 
Upvote 0
Glad you got it working....
Keep reading posts here to keep learning, we're all students ( well, me anyway)
 
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,807
Members
452,944
Latest member
2558216095

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