View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bernard Liengme[_3_] Bernard Liengme[_3_] is offline
external usenet poster
 
Posts: 1,104
Default sequential numbering exceptions

Helen,
In the subroutine below I have assumed the serial numbers are in column A,
rows 1 to 50
and that the error messages go in column D. You should eb able to see how to
change the columns to suit your need.
The 1 in line reading mytest = Cells(1, "A") must be changed if the
first numbers is in another row
And change the 2 and 50 in For j = 2 To 50 to match the row of the
second and last numbers
and fix Range("D1:D50").Clear and <<< Cells(j, "D") = "error as
needed

If you are new to macros
David McRitchie's site on "getting started" with VBA

http://www.mvps.org/dmcritchie/excel/getstarted.htm

Debra Dalgleish's "Adding Code to a Workbook"

http://www.contextures.com:80/xlvba01.html

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

Jon Peltier's site:
http://peltiertech.com/WordPress/200...e-elses-macro/

(General, Regular and Standard modules all describe the same thing.)


Sub tryme()
Range("D1:D50").Clear
mytest = Cells(1, "A")
oldchar = Mid(mytest, 1)
num1 = Mid(mytest, 2, 2) * 10000
temp = Mid(mytest, 4, 2)
If temp = "" Then
num2 = 0
Else
num2 = temp * 100
End If
temp = Mid(mytest, 6, 2)
If temp = "" Then
num3 = 0
Else
num3 = temp * 1
End If
oldnum = num1 + num2 + num3

For j = 2 To 50
mytest = Cells(j, "A")
newchar = Mid(mytest, 1)
num1 = Mid(mytest, 2, 2) * 10000
temp = Mid(mytest, 4, 2)
Debug.Print "*"; temp; "*"
If temp = "" Then
num2 = 0
Else
num2 = temp * 100
End If
temp = Mid(mytest, 6, 2)
If temp = "" Then
num3 = 0
Else
num3 = temp * 1
End If
newnum = num1 + num2 + num3

If newchar < oldchar Or newnum < oldnum Then
Cells(j, "D") = "error"
End If
oldchar = newchar
oldnum = newnum2

Next j
End Sub


best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email


"Helen" wrote in message
...
Easy exception reporting of sequential numbering.

I had a lengthy complex sequentially numbered worksheet by row. Lots of
things have now been added or taken away & I want a quick formulae to spot
errors in the numbering so I can amend them. The reason I can't just copy
&
paste from row 1 to the end is that there are 3 levels - it goes something
like this(with many more rows at each level!!):
S01 level 1 allocation
S0101 level 2 sub allocation
S010101 level 3 sub allocation
S010102 as above
S010103 as above
S0102 level 2 sub allocation
S02 level 1 allocation

Does this make sense? Does anyone have a solution please? I have about 50
worksheets of long coding to check!