View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
merjet merjet is offline
external usenet poster
 
Posts: 812
Default Sequential Number Generator Macro

See below. It assumes at least 1 entry in each of
21 columns; 1 column for each classification.

Hth,
Merjet

Sub NewCode()
Dim str1 As String
Dim str2 As String
Dim iNum As Integer
Dim iCol As Integer

On Error GoTo error_trap

str2 = "Enter class number -- 1-BLDG, 2-HSKG, 3-LCWM,"
str2 = str2 & " 4-MAIN, 5-UTIL , 6-LCWO, 7-ENRG, 8-AMGT,"
str2 = str2 & " 9-ITEA, 10-I&CS. 11-METR,12-EHSS, 13-EHSG,"
str2 = str2 & " 14-ITEH, 15-EHSR, 16-ITFP, 17-PLNG, 18-ACTG,"
str2 = str2 & " 19-ADMN, 20-SECT, 21-ITTC"
Do
'error will occur if InputBox returns blank
iCol = InputBox(str2)
iRow = Sheets("Sheet1").Cells(65536, iCol).End(xlUp).Row
str1 = Sheets("Sheet1").Cells(iRow, iCol)
iNum = Right(str1, Len(str1) - 4)
If iNum < 10 Then
str1 = Left(str1, 4) & "0" & iNum + 1
Else
str1 = Left(str1, 4) & iNum + 1
End If
Sheets("Sheet1").Cells(iRow + 1, iCol) = str1
Loop
error_trap:
End Sub
Sub