+ Reply to Thread
Results 1 to 8 of 8

Excel modifies my vba generated formula strings and causes errors (using @)

  1. #1
    Forum Contributor
    Join Date
    07-01-2018
    Location
    Adelaide, South Australia
    MS-Off Ver
    Office 365, & Excel 2016 on windows 10, & 14.7 for mac, & Excel 2015 for mac
    Posts
    173

    Excel modifies my vba generated formula strings and causes errors (using @)

    Hi all.
    I’m constructing a table where the user can define ranges of interest, and get quick overview of any errors in critical areas of the project.

    In order to avoid using a number of INDIRECT() calls, I thought I would simply have vba copy the range strings and generate the required formulas.
    However these are multi cell ranges, so to avoid #SPILL errors, I had to include an @ to enable implicit intersection.

    However when excel sets the formula string, it inserts an additional “@” to make them compatible with older versions, and this causes the formulas to show incorrect results.
    IE the expected
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    becomes
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    and
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    becomes
    Formula: copy to clipboard
    Please Login or Register  to view this content.



    How do I prevent excel from changing my formula strings?

    Here is my code, and an example work book is attached.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by truk2; 05-04-2021 at 12:28 AM. Reason: shared wrong formula
    If my solution helped, please consider adding Rep

  2. #2
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Excel modifies my vba generated formula strings and causes errors (using @)

    Please change .Formula to .Formula2


    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    07-01-2018
    Location
    Adelaide, South Australia
    MS-Off Ver
    Office 365, & Excel 2016 on windows 10, & 14.7 for mac, & Excel 2015 for mac
    Posts
    173

    Re: Excel modifies my vba generated formula strings and causes errors (using @)

    Thanks.

    But this is now showing me that my approach was wrong. It's entering the formulas correctly, but the formulas now ignore anything but the first cell in the range (or one that match the row/column of the formula). I now see that this is a property of Implicit Intersection. Any suggestions?

  4. #4
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Excel modifies my vba generated formula strings and causes errors (using @)

    No idea what you try to do.
    Maybe try

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    07-01-2018
    Location
    Adelaide, South Australia
    MS-Off Ver
    Office 365, & Excel 2016 on windows 10, & 14.7 for mac, & Excel 2015 for mac
    Posts
    173

    Re: Excel modifies my vba generated formula strings and causes errors (using @)

    Quote Originally Posted by Bo_Ry View Post
    No idea what you try to do.
    I'm trying to look at a range, and have the formula return details about any errors that occurred.
    Column "D" should return true if there are any errors in the range.
    Column "E" attempts to return to the Type of the error, but this is optional
    Column "F" is just a text lookup based on column "E", also optional.


    Quote Originally Posted by Bo_Ry View Post
    Maybe try

    Please Login or Register  to view this content.
    The problem here is that by not inserting an @, and using .formula, the "@" is automatically added at the range statements, meaning that the ranges are treated as a single cell.
    The formula in "D" returns true when there is no error, and False when there is an error, the opposite of expected behavior.


    If I try the same with .formula2, I get spill errors from the Dynamic Arrays calc.

    And if I insert the intersect operator myself, and use .formula2 (as you suggested before) it also doesn't work.


    I don't see a way forward at the moment.

  6. #6
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Excel modifies my vba generated formula strings and causes errors (using @)

    Maybe try

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    07-01-2018
    Location
    Adelaide, South Australia
    MS-Off Ver
    Office 365, & Excel 2016 on windows 10, & 14.7 for mac, & Excel 2015 for mac
    Posts
    173

    Re: Excel modifies my vba generated formula strings and causes errors (using @)

    Thanks Bo_Ry. This works perfectly.

    I'm not sure I understand though.
    Why is the lookup value a '9' in
    Please Login or Register  to view this content.
    ?

    Thanks again

  8. #8
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Excel modifies my vba generated formula strings and causes errors (using @)

    9 can be any large number that more than the number from ERROR.TYPE

    9 can lookup for 0-9
    20 can lookup for 0-20

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Why are #Value! errors being generated in this spreadsheet?
    By Aceso in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-31-2013, 03:15 PM
  2. % of days worked and errors generated
    By andycuk7 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-06-2012, 09:40 AM
  3. Data validation formula modifies itself
    By j.a.mcguire in forum Excel General
    Replies: 3
    Last Post: 07-08-2010, 02:47 PM
  4. Replies: 11
    Last Post: 03-21-2006, 03:30 AM
  5. [SOLVED] Excel has generated Errors
    By Denz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-12-2005, 04:30 PM
  6. EXCEL.exe has generated errors and will be closed by Windows
    By Mike Fabrico in forum Excel General
    Replies: 1
    Last Post: 07-18-2005, 02:05 PM
  7. Replies: 0
    Last Post: 03-15-2005, 03:06 PM
  8. Replies: 1
    Last Post: 02-14-2005, 04:52 PM

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