Results 1 to 4 of 4
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Referring to cells pt 2 (XL97/WinNT4)

    Could someone tell me how I go about referring to a cell in a formula that is only going to be set when the code is run (and will change each time it is run!)?

    That is, I have this line of code:

    .Cells(intNStartRow + 6, 6).Formula = "=IF(E11=""-"",""-"", ((1+E11/200)^2-1)*100)"

    But E11 should be replaced with whichever cell would be covered by intNStartRow + 6, 5 - that is, it's calculating on the value of the cell to its left, bearing in mind that if it's a - (hyphen) then it should ignore the calculation and just put another hyphen in.

    I'd be grateful if someone would either point me in the right direction if it's possible, or indicate how to do it in code if it's not!

    Ta muchly
    Beryl M


  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Referring to cells pt 2 (XL97/WinNT4)

    Beryl,
    The easiest way is to use something like:
    .Cells(intNStartRow + 6, 6).FormulaR1C1 = "=IF(RC[-1]=""-"",""-"", ((1+RC[-1]/200)^2-1)*100)"
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Referring to cells pt 2 (XL97/WinNT4)

    Umm - don't worry, peeps, I had a rush of something to the brain and worked it out for myself - I needed to break the code with the variable, like so:

    .Cells(intNStartRow + 6, 6).Formula = "=IF(" + .Cells(intNStartRow + 6, 5).Address + "=""-"",""-"", ((1+" + .Cells(intNStartRow + 6, 5).Address + "/200)^2-1)*100)"

    I don't know, maybe this will be useful to someone else!
    Beryl M


  4. #4
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Referring to cells pt 2 (XL97/WinNT4)

    Thanks, Rory - I had worked out a (far less elegant) solution for myself, which I was just typing as you posted your one - but I think I prefer yours, so I'm going to use that ...

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Beryl M


Posting Permissions

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