Convert this snippet to function?

rogster001

New Member
Joined
Jun 17, 2010
Messages
45
Hi all,

Further to my somewhat garbled post yesterday, i think the problem amounts to this:

Code:
if(row_number <= currentWeekValue)
{
    cell[row][column] = (do a sum function or simple arithmetic operation)
}

I am going to have a bash at getting this syntax in excel, but could anbody also give any tips on a possible function statement to implement this?

cheers
 

Some videos you may like

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

rogster001

New Member
Joined
Jun 17, 2010
Messages
45
Code:
if(row_number <= currentWeekValue)
{
    cell[row][column] = (do a sum function or simple arithmetic operation)
}

I am sorry, I mean it to be interpreted as pseudo code really, although it is valid C/ C++

I think to interpret this as an excel statement i would mean the following for the variables,

row_number would be the worksheet row number, or if column A was the index of say, week numbers, then it would be the value in that row, column position.

currentWeekValue i mean to be a variable that is known to 'everything' across the worksheet, so that when i come to update the reports on a monday morning, i can just change currentWeekValue from say, 10, to 11 and the rest would follow...

I think i can acheive this with the following in Excel...thank you for reading this far! :

I think i need to define a "name" and call it currentWeekValue ?
I have an If statement sorted out that i think i could combine with the defined name to get what i need:

As a test i did this:

=IF(A1 = 10, "contains 10, true","does not contain 10, false")

#which workws great.

So i think i can nest this with the name and that should work??
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
If you have defined the name currentWeekValue, in a cell other than A1 or B1:

=IF(A1=currentWeekValue,B1,"")

will return what's in B1 if True, otherwise null.
 

rogster001

New Member
Joined
Jun 17, 2010
Messages
45
Thank you,

So i now have this...which seems to work a treat:

For example
=IF(A1=10,SUM(B1+B2),"")

Now i just have to cross my fingers and hope i can get the name define happening ok..
i think that should be fine though.

It would be useful to be able to edit the current week, ie 'name' value directly via a cell or small input box, Is this a possibility or am i overegging the pudding and should just use the Insert > Names > define etc from the menu?

EDIT:
I think i have that now, it is just the value in cell itself where the name was created.. so i just edit the contents of that cell!
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,108,709
Messages
5,524,433
Members
409,577
Latest member
Dwg

This Week's Hot Topics

Top