Auto increment numbering based on a cell value

stirlingmw

Board Regular
Joined
Feb 18, 2013
Messages
75
Good morning all
I have a worksheet "Quiz" which displays random questions taken from a question bank. These questions are annotated into column B4 onwards, based on the number of questions requested. I am trying to number these questions using VBA, but cannot find any code which seems to work.
I have left Column A bank when the questions are added to the worksheet, if any text is present in cell in column B i would like column A to show a sequential number from 1 to n dependant on the number questions generated, so if Text is present in B4, Cell A4 shows 1, B5 text is present, A5 show 2 etc. There will never be a gap in column B as all questions are annotated into the next available blank row.

TIA

Steve
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Try with this,
Code:
With Range("A4:A" & Range("B" & Rows.Count).End(xlUp).Row)
    .Cells(1, 1).Value = 1
    .DataSeries Rowcol:=xlColumns, Type:=xlLinear, Step:=1, Trend:=False
End With

Regards,
Dhruva
 
Upvote 0
Dhruva

Works perfect thank you.

I have also just figured that if i use the following code attached to the worksheet it also works.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cell As Range
    If Not Intersect(Range("B4:B100"), Target) Is Nothing Then
        For Each cell In Intersect(Range("B4:B100"), Target).Cells
            If cell.Value <> "" And Range("A" & cell.Row).Value = "" Then
                Range("A" & cell.Row).Value = Application.Max(Range("A4:A100")) + 1
            End If
        Next
    End If
End Sub
Your solution is slicker. thanks again
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,877
Messages
6,127,500
Members
449,385
Latest member
KMGLarson

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