+ Reply to Thread
Results 1 to 2 of 2

Search/Replace String to Formula conversion

Hybrid View

  1. #1
    Registered User
    Join Date
    01-06-2008
    Posts
    1

    Search/Replace String to Formula conversion

    Cannot reliably predict whether Excel will treat cell as a string or formula when I have a string: '=Sum(A1:A4) [say]
    ...and proceed to Search/Replace '=Sum with =Sum;
    Sometimes will evaluate and sometimes will not.

    >>My VBA solution is as follows -
    but I would like to know a native Excel solution (if it exists).
    '-----
    Sub Toggle_Formula()
    Dim oCell As Range
    'This sub will toggle a cell between string/formula
    'Sometimes you can achieve this with a search replace...sometimes not
    '...and I cannot determine exactly when or why this Excel behaviour changes.
    'Hence this function - which seems to work as required.

    For Each oCell In Selection
    If oCell.Formula = oCell Then
    'Note this expression will force Excel to evaluate!!
    '=============================
    oCell.Formula = oCell.Formula
    '=============================
    Else
    oCell.Formula = "'" & oCell.Formula
    End If
    Next oCell
    End Sub

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Please read the forum rules and edit your post to add code tags.

+ 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