Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 67027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:11:44+00:00 2026-05-10T19:11:44+00:00

Let’s say that I create a Sub (not a function) whose mission in life

  • 0

Let’s say that I create a Sub (not a function) whose mission in life is to take the active cell (i.e. Selection) and set an adjacent cell to some value. This works fine.

When you try to convert that Sub to a Function and try to evaluate it from from spreadsheet (i.e. setting it’s formula to ‘=MyFunction()’) Excel will bark at the fact that you are trying to affect the value of the non-active cell, and simply force the function to return #VALUE without touching the adjacent cell.

Is it possible to turn off this protective behavior? If not, what’s a good way to get around it? I am looking for something a competent developer could accomplish over a 1-2 week period, if possible.

Regards, Alan.

Note: I am using 2002, so I would favor a solution that would work for that version. Having that said, if future versions make this significantly easier, I’d like to know about it too.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T19:11:45+00:00Added an answer on May 10, 2026 at 7:11 pm

    It can’t be done, which makes sense because:

    • When a worksheet function is called, the cell containing the function is not necessarily the active cell. So you can’t find the adjacent cell reliably.

    • When Excel is recalculating a worksheet, it needs to maintain dependencies between cells. So it can’t allow worksheet functions to arbitrarily modify other cells.

    The best you can do is one of:

    • Handle the SheetChange event. If a cell containing your function is changing, modify the adjacent cell.

    • Put a worksheet function in the adjacent cell to return the value you want.

    Update

    Regarding the comment: ‘I’d like this function to work on a ‘blank’ spreadsheet, so I can’t really rely on the SelectionChange event of spreadsheets that may not yet exist, but will need to call this function’:

    • Can you put your function in an XLA add-in? Then your XLA add-in can handle the Application SheetChange (*) event for all workbooks that are opened in that instance of Excel?

    Regarding the comment: ‘Still, if you keep Excel at CalculationMode = xlManual and fill in just values, you should be just fine’

    • Even when CalculationMode is xlManual, Excel needs to maintain a dependency tree of references between cells so that it can calculate in the right order. And if one of the functions can update an arbitrary cell, this will mess up the order. Which is presumably why Excel imposes this restriction.

    (*) I originally wrote SelectionChange above, corrected now – of course the correct event is SheetChange for the Workbook or Application objects, or Change for the Worksheet object.

    Update 2 Some remarks on AlanR’s post describing how to ‘kinda’ make it work using a timer:

    • It’s not clear how the timer function (‘Woohoo’) will know which cells to update. You have no information indicating which cell contains the formula that triggered the timer.

    • If the formula exists in more than one cell (in the same or different workbooks), then the UDF will be called multiple times during a recalculation, overwriting the timerId. As a result, you will fail to destroy the timer reliably, and will leak Windows resources.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 105k
  • Answers 105k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Rather than creating an EntityKey create a stub Gender object… May 11, 2026 at 8:45 pm
  • Editorial Team
    Editorial Team added an answer In the latter version the using directives only apply within… May 11, 2026 at 8:45 pm
  • Editorial Team
    Editorial Team added an answer It's actually a bad idea to try and control threads… May 11, 2026 at 8:45 pm

Related Questions

Let's say you create a wizard in an HTML form. One button goes back,
Let's say I'm building a data access layer for an application. Typically I have
Let's say you have a class called Customer, which contains the following fields: UserName
Let me try to explain what I need. I have a server that is
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.