Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

Excel 2003 a problem similar to finding first non zero value

Mar 24, 2010 9:10PM PDT

Hi,

I have a block of data in excel, representing monthly customer sales.

The data is laid out with first 2 columns as customer number and name, and then 36 columns of figures. These columns are headed by the year and month in the format YYYYMM in the first row.

The problem is I need to add a column C to find the first month each customer started trading.

In plain text, I want the formula to find the first entry in the row that isn't zero, then look at row 1 in that column, to return the year and month number for the first time that customer had turnover.

As there are several hundred rows of data, and several sets of data, this is too big to do manually.

Does anyone have a solution to this one ?

Many Thanks

Discussion is locked

- Collapse -
Re: finding value
Mar 24, 2010 9:23PM PDT
- Collapse -
re: Finding value
Mar 24, 2010 9:38PM PDT

Hi,

I understand how to create a custom function, I am stuck on the couple of lines of code in the middle.

What I want to do is start at the first cell in the row, and counts the cells across that are either blank or zero. The first cell found that is not blank or zero, return that number as the result of the function. So if there are 5 cells blank or zero, and the 6th contains a value, then the function would return the answer '6'

Once I have that number, I can use it in an OFFSET formula to get the value I want.

- Collapse -
Re: looping through a row.
Mar 25, 2010 11:36PM PDT

The essential piece of code consists of a loop using the statement
activecell.offset(0,1).activate
This statement makes the cell on the same row, one column to the right, the active cell. Then see if it's filled.

The whole algoritm in pseudocode:
- select first cell of current row;
- make it active
- set counter to 0
- while cell is empty and there are more columns to do:
-- increment counter;
-- make next cell active
- if end of range reached
-- there's no sale at all
- else
-- the counter gives the column

Kees