Excle auto-increment sequence number

Source: Internet
Author: User

Press Alt + F11 to enterCodeEdit
Copy the following code to the editing window:
Private sub worksheet_change (byval target as range) 'worksheet change event causes the followingProgram
Application. enableevents = false' the event is forbidden.
X0 = activecell. row' X0 = number of active cells
If x0> 1 then' x0 is above 2
Cells (x0, 1) = cells (x0-1, 1) + 1' x0 rows = X0-1 rows + 1
Else: cells (x0, 1) = 1' when x0 is 1 = 1
End if 'end condition judgment
Do while cells (x0 + 1, 1) <> "'x0 + 1 rows are not empty.
Cells (x0 + 1, 1) = cells (x0, 1) + 1' cells x0 + 1 rows = x0 rows + 1
X0 = x0 + 1' x0 incremental execution
Loop 'returns the while statement
Application. enableevents = true' event triggered
End sub 'End the program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.