+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    03-10-2010
    Location
    England, Enlandshire
    MS-Off Ver
    Excel 2007
    Posts
    4

    How to reference cell properties where function is written?

    Hi, new to this forum, and pretty much new to vba programming.

    I'm using Excel 2007, and I have a particular problem re. referencing the "current cell" data

    My formula requires that I make reference to the cell property row and column.

    I can write my formula so that it works correctly, however I would like the formula to update if the spreadsheet changes.

    The trouble is, I have references the cell propery using activecell.cell and activecell.column.

    If I make the formula update then if my cursor isn't on the cell where the formula is, the activecell references are wrong, and the formula then displays the wrong result.

    Is there any way that I can reference the cell properties, no matter where the cursor is, so that my formula will work if I make it updateable?

    Many thanks in advance.
    Last edited by Lepista; 03-10-2010 at 07:41 AM.

  2. #2
    Forum Guru rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: How to reference cell properties where formula is written?

    Welcome,

    Without seeing the actual code, it is hard to give you advice. Please copy, paste your code in a post, select it and press the # sign in the (advanced) editor.

    Without seeing the code, the ActiveCell changes if you use code like
    Code:
    range.select
    best is to make your own variable like
    Code:
    Dim MyRng as Range
    and reference this to the range you a working with
    Code:
    Set MyRng = range("A1:B2")
      With MyRng
      'etc
      End With
    hope this helps
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  3. #3
    Registered User
    Join Date
    03-10-2010
    Location
    England, Enlandshire
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: How to reference cell properties where formula is written?

    Thanks, that is pretty much the crux of the problem.

    Apologies - I wrote "formula" in the title, where I meant to put "function".

    I need the formula to have a different value for "column", for example, if the formula is in cell B2, than if it's in cell B3.

    I want the formula to be in many cells within a sheet, and for each of them to update

    I currently have

    Code:
    Function Ratio
    .
    .
    .
    RAT = ActiveCell.Row
    .
    .
    .
    End function
    The first time I imput the formula in a cell, activecell is the correct loation, however if I update the sheet, then this recalculatees, and activecell is not correct.

    I would like the function to always reference the cell that it is in, rather than "activecell".
    Last edited by teylyn; 03-10-2010 at 06:55 AM.

  4. #4
    Registered User
    Join Date
    03-10-2010
    Location
    England, Enlandshire
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: How to reference cell properties where formula is written?

    Maybe a little more clarification,

    I don't want to reference
    Code:
    activecell.row
    I want to reference
    Code:
    cell_that_function_is_in.row
    Last edited by Lepista; 03-10-2010 at 07:07 AM.

  5. #5
    Forum Moderator teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    2003 & 2010
    Posts
    10,042

    Re: How to reference cell properties where formula is written?

    Lepista, I added code tags to your post. Please have a look at the forum rules to find out why you need to use them if you post code.
    teylyn
    Microsoft MVP - Excel
    At Excelforum, you can say "Thank you!" by clicking the icon below the post.

    Avoid pie charts with more than two data points. Why? See here (pdf, 559 kb). The only acceptable pie chart is here.

  6. #6
    Forum Moderator romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Alibi
    MS-Off Ver
    All
    Posts
    8,262

    Re: How to reference cell properties where function is written?

    What you need is Application.Caller:
    Code:
    RAT = Application.Caller.Row
    So long, and thanks for all the fish.

  7. #7
    Registered User
    Join Date
    03-10-2010
    Location
    England, Enlandshire
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: How to reference cell properties where function is written?

    Cheers RS - spot on!
    Last edited by teylyn; 03-10-2010 at 07:53 AM. Reason: removed spurious qoute

  8. #8
    Forum Moderator teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    2003 & 2010
    Posts
    10,042

    Re: How to reference cell properties where function is written?

    Lepista, please don't quote whole posts. Why quote at all, if you are responding to the post directly above???
    teylyn
    Microsoft MVP - Excel
    At Excelforum, you can say "Thank you!" by clicking the icon below the post.

    Avoid pie charts with more than two data points. Why? See here (pdf, 559 kb). The only acceptable pie chart is here.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0