+ Reply to Thread
Results 1 to 6 of 6

Get current cell with VBA function

  1. #1
    vbphil
    Guest

    Get current cell with VBA function

    I've written a VBA function that will be used on a worksheet as a worksheet
    function. I want to modify the formatting of the cell that the function is
    in. I haven't found any way that works. How do you reference the cell that
    the formula is in and make changes to it?

    Thanks, -phil
    --
    no place like 127.0.0.1

  2. #2
    Don Guillett
    Guest

    Re: Get current cell with VBA function

    maybe

    activecell.

    format(activecell,"yourformathere")

    --
    Don Guillett
    SalesAid Software
    [email protected]
    "vbphil" <[email protected]> wrote in message
    news:[email protected]...
    > I've written a VBA function that will be used on a worksheet as a

    worksheet
    > function. I want to modify the formatting of the cell that the function is
    > in. I haven't found any way that works. How do you reference the cell that
    > the formula is in and make changes to it?
    >
    > Thanks, -phil
    > --
    > no place like 127.0.0.1




  3. #3
    vbphil
    Guest

    Re: Get current cell with VBA function

    ActiveCell doesn't compute in a function called from a worksheet formula. It
    only works from within a VBA macro call.

  4. #4
    Don Guillett
    Guest

    Re: Get current cell with VBA function

    Perhaps you should post your udf and telll us exactly what you want to do

    --
    Don Guillett
    SalesAid Software
    [email protected]
    "vbphil" <[email protected]> wrote in message
    news:[email protected]...
    > I've written a VBA function that will be used on a worksheet as a

    worksheet
    > function. I want to modify the formatting of the cell that the function is
    > in. I haven't found any way that works. How do you reference the cell that
    > the formula is in and make changes to it?
    >
    > Thanks, -phil
    > --
    > no place like 127.0.0.1




  5. #5
    JE McGimpsey
    Guest

    Re: Get current cell with VBA function

    Functions, including User Defined Functions, cannot change the
    formatting of a cell.

    To do that you'd need an event macro in the worksheet or workbook code
    module, e.g., Worksheet_Change, or Worksheet_Calculate.

    If you post what you're trying to do, it would be easier to suggest a
    solution.


    In article <[email protected]>,
    vbphil <[email protected]> wrote:

    > I've written a VBA function that will be used on a worksheet as a worksheet
    > function. I want to modify the formatting of the cell that the function is
    > in. I haven't found any way that works. How do you reference the cell that
    > the formula is in and make changes to it?


  6. #6
    vbphil
    Guest

    Re: Get current cell with VBA function

    You have answered the basis of my question. It can't be done this way.
    Here's a greatly simplified example. I just wanted to know if you can
    access the range object or cell of where the formula is entered besides just
    settings it value.

    'the worksheet cell formula would be "=setFormat()"

    function setFormat() as string
    'set the font of this cell to bold or set the color
    .......
    'set the cell value
    setFormat = "test"
    end function


    Thanks for the feedback, -phi
    "JE McGimpsey" wrote:

    > Functions, including User Defined Functions, cannot change the
    > formatting of a cell.
    >
    > To do that you'd need an event macro in the worksheet or workbook code
    > module, e.g., Worksheet_Change, or Worksheet_Calculate.
    >
    > If you post what you're trying to do, it would be easier to suggest a
    > solution.
    >
    >
    > In article <[email protected]>,
    > vbphil <[email protected]> wrote:
    >
    > > I've written a VBA function that will be used on a worksheet as a worksheet
    > > function. I want to modify the formatting of the cell that the function is
    > > in. I haven't found any way that works. How do you reference the cell that
    > > the formula is in and make changes to it?

    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.6.0 RC 1