Trying to have this code generate only a numerical value list by rows: 1, 2, 3, ... 10, 11

J

John Tudor

Originally this was used to create an alpha listing. I use this to
create hiearchy and need the code to count upwards from 1 by 1 as high
as is needed. (probably at least to three digits).

Code being used:

lastletter = "1"

Cells(2, 16) = lastletter
For intalpha = 3 To Cells(65536, 3).End(xlUp).Row

If Cells(intalpha, 2) = 0 Then lastletter = Chr(Asc(lastletter) + 1)
Cells(intalpha, 16) = lastletter
Next intalpha

** Posted via: http://www.ozgrid.com
Excel Templates, Training, Add-ins &
Software!http://www.ozgrid.com/Services/excel-software-categories.htm **
 
D

Dave Peterson

Your code looks like you're only incrementing that counter if the value in
column B is 0. Otherwise, it stays the same as the one you just used.

If that's correct, you could drop the strings and just use numbers:

Option Explicit
Sub testme01()

Dim iCtr As Long
Dim iRow As Long
Dim lastRow As Long

iCtr = 1
With ActiveSheet
lastRow = .Cells(.Rows.Count, 3).End(xlUp).Row
.Cells(2, 16).Value = iCtr
For iRow = 3 To lastRow
If .Cells(iRow, 2).Value = 0 Then
iCtr = iCtr + 1
End If
.Cells(iRow, 16).Value = iCtr
Next iRow
End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top