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