Home

Macros and Programming

 

CardboxForumsMacros and Programming > "insert a new row after a break in a number sequence"

insert a new row after a break in a number sequence

i need help to write a macro to insert a new row after a break in a number sequence

Current user: [none]
Register / Log In · Help

Posted By Post

TALON123

26-Sep-2008 11:24

i need help to write a macro to insert a new row after a break in a number sequence.
for exsample.
1
2
3
5
6
7

would be

1
2
3

5
6
7

Any ideas

Charles Welling

9-Oct-2008 14:10

I finally had some time to make this little macro for you. Change the field "MyField" into your own field. The macro splits your field into separate lines and counts them. Then an empty "newfield" is made. Every line is compared to the next line to see if the difference is "1". The current line is added to the variable "newfield" and if the difference is greater than "1", an empty line is added as well. Because the counter goes beyond the number of lines (counter+1) and this would result in an error, the macro checks this and terminates as soon as the end is reached. The last line is added to "newfield" without comparison (there's no next line to compare it with). The original content of the field is replaced by "newfield".

lines = split(fields("MyField"),CHR(10))

NumberofLines = 0
for each line in lines
NumberofLines = NumberofLines + 1
next

newfield = ""

for counter = 0 to NumberofLines-1
if counter+1 = NumberofLines then
newfield = newfield + lines(counter)
Fields("MyField")=newfield
halt
end if

if lines(counter+1) - lines(counter) > 1 then
newfield = newfield & lines(counter) & CHR(10) & CHR(10)
else
newfield = newfield & lines(counter) & CHR(10)
end if
next

Quick Reply

Please log in or register before trying to post a reply.

 
© 2010 Cardbox Software Limited   Home