If like me you find resizing array formulas awkward, you will find the
following code to a time-saver.  It will automatically create an array
formula to fit the currently selected cells, using the formula or
value that is in the top left cell of your selection.

I've put this code in an add-in called TechnicanaUtilities and will
upload this to the files section of this site.  If you load the add-
in, it will automatically run the code each time you press CTRL+SHIFT
+A together.

Regards,

Chris Spicer
www.Technicana.com

' Distributed under the Creative Commons licence at
http://creativecommons.org/licenses/by/2.0/uk/legalcode
Public Sub ResizeArray()
    ' Resizes an Array formula.  Changes whatever is in the top left
cell
    ' of the selection to an array covering the entire selection.

    Dim rngCurrent As Range
    Set rngCurrent = Selection

    ' Get the Contents of the Top Left Cell
    Dim vContents As Variant
    vContents = rngCurrent.Cells(1, 1).Formula

    ' Clear the current selection
    On Error GoTo FailedToClear
    ClearRange rngCurrent

    ' Set the current selection to be  array formula
    rngCurrent.FormulaArray = vContents

    Exit Sub

FailedToClear:
    MsgBox Title:="Failed to clear the selected range.", _
            Prompt:="This can be caused by the presence of another
array function within the bounds of the selection"
    Exit Sub
End Sub

Private Sub ClearRange(rng As Range)
    ' Clear the Current Range, including any arrays in the
    ' range.
    If rng.Cells(1, 1).HasArray Then
        rng.CurrentArray.Clear
    Else
        rng.Clear
    End If
End Sub

--~--~---------~--~----~------------~-------~--~----~
----------------------------------------------------------------------------------
Some important links for excel users:
1. Excel and VBA Tutorials(Video and Text), Free add-ins downloads at 
http://www.excelitems.com
2. Excel tutorials at http://www.excel-macros.blogspot.com
3. Learn VBA Macros at http://www.vbamacros.blogspot.com
4. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 

To post to this group, send email to excel-macros@googlegroups.com
If you find any spam message in the group, please send an email to:
Ayush Jain  @ jainayus...@gmail.com or
Ashish Jain @ 26may.1...@gmail.com
<><><><><><><><><><><><><><><><><><><><><><>
HELP US GROW !!

We reach over 5,200 subscribers worldwide and receive many nice notes about the 
learning and support from the group. Our goal is to have 10,000 subscribers by 
the end of 2009. Let friends and co-workers know they can subscribe to group at 
http://groups.google.com/group/excel-macros/subscribe
-~----------~----~----~----~------~----~------~--~---

Reply via email to