Thread: numbering cells
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default numbering cells

Code like the following will number the rows, skipping blanks. In the
code, change

Const COL As String = "A"
to the column letter in which the number should be placed.

Const TEST As String = "B"
to the column letter of the cell that if blank indicates that the row
is not to be numbered.

Const START_ROW = 1
to the first row of data to test.

Set WS = Worksheets("Sheet1")
to the name of the appropriate worksheet


Sub NumberCells()
Const COL As String = "A"
Const TEST As String = "B"
Const START_ROW = 1

Dim N As Long
Dim L As Long
Dim LastRow As Long
Dim WS As Worksheet
Set WS = Worksheets("Sheet1")
With WS
LastRow = .Cells(.Rows.Count, TEST).End(xlUp).Row
End With
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
.EnableEvents = False
End With
With WS
For N = START_ROW To LastRow
If Len(.Cells(N, TEST).Value) 0 Then
L = L + 1
.Cells(N, COL).Value = L
End If
Next N
End With
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
.EnableEvents = True
End With
End Sub


Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]





On Fri, 4 Dec 2009 08:58:01 -0800, Soth
wrote:


Hi-

I have over 200,000 lines and I'd like to numbering each cell 123...etc.
The problem is some cells are blank and I can't seem to do as much auto
refill and it just time consuming to drag cell all the way to 200K line. So
i'm wondering if there is a quickest way to numbering cell from 1 through
200000

Thanks
Soth