+ Reply to Thread
Results 1 to 3 of 3

Force an Array Formula using VBA

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Force an Array Formula using VBA

    I've have the following code which when run allows me to 'comment out' and 'uncomment' a range of formula on a worksheet which works really well, however I've now had to change one of the formula to an array formula using CTRL, SHIFT, ENTER. Is there any way to adapt the code so that when uncommented it forces the array formula to remain as array formula? At the moment when uncommenting the array formula no longer remain as array formula?

    This is my array formula

    {=SUM('C:\Folder1\Folder2\Folder3\Folder4\[FileName]Sheet1'!$A:$A)}
    and this is the code

    Sub CommentOut()
        Dim c As Range
            On Error Resume Next
            For Each c In Selection.SpecialCells(xlCellTypeFormulas)
        c.Formula = "'" & c.Formula
            With Selection.Font
            .ThemeColor = xlThemeColorDark1
            .TintAndShade = 0
        End With
    Next c
        If Err = 0 Then MsgBox "Formulas Commented Out", vbInformation
        On Error GoTo 0
    End Sub
    
    Sub Uncomment()
    Dim c As Range
    On Error Resume Next
    For Each c In Selection.SpecialCells(xlCellTypeConstants)
        c.Formula = Replace(c.Formula, "'=", "=")
            With Selection.Font
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
        End With
    Next c
    If Err = 0 Then MsgBox "Formulas Restored", vbInformation
    On Error GoTo 0
    End Sub
    Many thanks
    Last edited by HangMan; 07-30-2015 at 04:53 AM.

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,446

    Re: Force an Array Formula using VBA

    Hi,

    DOes this work for you?

    c.FormulaArray = Replace(c.Formula, "'=", "=")
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Force an Array Formula using VBA

    Hi sweep,

    It certainly does, many thanks...

+ 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. Replies: 6
    Last Post: 04-25-2014, 10:31 AM
  2. How to force excel to drag formula by two, rather than one.
    By sasiddiq in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-17-2014, 12:58 PM
  3. force array formula in cell
    By Leon V (AW) in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-04-2013, 10:34 AM
  4. Force destination formatting
    By krumel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-13-2013, 11:31 PM
  5. Force a formula to use the format I want.
    By Banaticus in forum Excel General
    Replies: 1
    Last Post: 02-06-2010, 08:25 AM
  6. [SOLVED] Force a formula from a different sheet.
    By all4excel in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-07-2008, 11:04 AM
  7. How to force a formula to calculate its value?
    By surotkin in forum Excel General
    Replies: 3
    Last Post: 04-14-2005, 06:14 PM

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