Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sequencing in Excel 1

Status
Not open for further replies.

ahbyun

Technical User
Dec 11, 2004
9
0
0
KR
I have 31 rows of information on EXCEL.
One of the columns is Sequence.

I want to use VB Editor in Excel to do the following.

I want to automatically make the Sequence column to have a number from 1 to the number of rows of information.

So it would look like this:

Sequence Customer SN
1 Ray 1232131
2 Steve 4994922
3 Jason 4521233
.
.
.

so the sequence of 1, 2, 3 would automatically appear since there are 3 rows of information...

What would be the best method for this situation?
Thank you!
 
Can you be a little more specific ?

How is this data placed in Excel ? Manually entered, and automatically sequence a number as you enter a new row of data ?
Is the data imported ? What ?

John Borges
 
Data is imported
Original Data has Customer and SN column.

I added the Sequence Column and I want to be able to Number the rows according to the Data.
 
well...

if you have an unbroken column (no gaps) such as column 2 (aka B) you could do something like...

Code:
'Starting positions:
Seq = 1 'Sequence #
C = 2   'Column #
R = 2   'Row #
While Cells(R, C) <> ""
  Cells(R, 1) = Seq
  R = R + 1
  Seq = Seq + 1
Wend

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Try this:

In Your Sheet VB Editor,

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
  Dim C As Long
  Dim R As Long
  Dim Seq As Long

  Application.EnableEvents = False

  Seq = 1 'Sequence #
  C = 2   'Column #
  R = 2   'Row #

  Do While Cells(R, C).Value <> ""
    Cells(R, 1) = Seq
    R = R + 1
    Seq = Seq + 1
  Loop

  Application.EnableEvents = True

End Sub
Everytime you add new entry on column 2 or delete or import, this will adjust itself to count from 1 to whatever.

John Borges
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top