Results 1 to 4 of 4

Thread: [Excel 2007] How do I program this simple function?

  1. #1

    Thread Starter
    Lively Member Yumby's Avatar
    Join Date
    Feb 2009
    Posts
    120

    [Excel 2007] How do I program this simple function?

    I'm using a function to put a price in a cell depending on how many days have passed. So 1 day = $10, 2 days = $20, 3 days = $30 and I do it like this...

    A1 (start date) = 01/01/2011
    B1 (end date) = 01/01/2011
    C1 (days) = 1
    D1 (price) = $10

    But after 30 days I want to put in a discounted price (so 31 days would be $305 not $310) and this is where I get stuck. My code goes something like this (I'm not in front of the same computer right now)...

    Code:
    elseif days > 30 then
    x = range("c31") - 30
    price = 300 + (x * 5)
    Initially the code worked but then after copying and pasting the code into other cells/rows below it, I was getting the wrong result. I think it's because I'm referencing the cell directly "C31". I think I need to program it so that when I copy and paste the cells contents the reference to the cell changes too (eg - C31 to C32) but I can't work out how to fix this problem. So can anyone point me in the right direction? Thanks.

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: [Excel 2007] How do I program this simple function?

    I would say:
    Code:
    elseif days>30 then
       price=300+((days-30)*5)
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3

    Thread Starter
    Lively Member Yumby's Avatar
    Join Date
    Feb 2009
    Posts
    120

    Re: [Excel 2007] How do I program this simple function?

    Thanks opus. I'll give it a shot when I can and I'll let you know how I go.

  4. #4
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: [Excel 2007] How do I program this simple function?

    As a possibly silly question - why in code? Can't you do one or two columns with the results and use a function to give you the results?


    Complicated formulae but you needn't use code (unless you are are already and its to put it in place...)


    Hope those who have posted already have given you the answer you need.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width