Use VBA to find the number of columns in Excel that are not empty for the first time in a row of columns and the last column is not empty

Source: Internet
Author: User

Yesterday, colleagues had a need to know the month of the first sale of each item, and the month of the last sale. I want to use what Excel function to solve, but found a half-day did not find the right, and finally through the VBA to solve it.

How to use:

Excel Tools-Macro-visual Basic Editor right-click in the left column,

Insert-Module

Then enter:


1 FunctionLast0 (ByValInt_row as Integer) as Integer2Last0 = -3      Do  whileCells (Int_row, Last0) =""  andLast0 >=34Last0 = Last0-15     Loop6 7 End Function8 9' It is important to note that the return value of a function seems to be a very wonderful requirement for a variable to be consistent with the method name ....Ten FunctionFrist0 (ByValInt_row as Integer) as Integer OneFrist0 =3 A      Do  whileCells (Int_row, Frist0) =""  andFrist0 <=255 -Frist0 = Frist0 +1 -     Loop the     IfFrist0 >255  Then -Frist0 =8888 -     End If - End Function

You can then refer directly to the cell in the unit

For example: =frist0 (4) The return value is the column number of the first cell in line 4 that is not 0.

If the function returns 8888, it indicates that there is no data for this row.

Use VBA to find the number of columns in Excel that are not empty for the first time in a row of columns and the last column is not empty

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.