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
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

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:
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,031
Messages
5,856,937
Members
431,841
Latest member
jaybeem

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top