excel array formula: not have to 'ctrl-shift-enter'? [closed]

戏子无情 提交于 2019-12-08 03:56:51

问题


After you press f2 to edit an array formula e.g. {=MATCH(TRUE,(B2:B100)>0,0)}, the curly brackets disappear of course. After editing, you have to press ctrl + shift + enter to make the curly brackets reappear.

Is there some setting to keep the {} even if you press a normal ‘enter’?

Also after copying the cell above (i.e. containing the array formula) you cannot paste it onto say 10 x other cells. You can only paste it onto one new cell at a time. Is there a way to paste onto more than one cell at once?

Thanks


回答1:


The array formula should copy and paste fine and retain it's array as long as you copy the cell rather than copy the formula in the formula bar. It also copies fine if you drag/fill the cell down or across. It may be if you want to keep the range B2:B100 when dragging then use $B$2:$B$100 to stop it incrementing.

F4 is a nice short cut that can help here. Position your cursor over B2:B100 and press F4.

If you want to enforce certain cells always retain formula array I can think of a dirty workaround but I think it may have more negatives than positives.

Negatives:

-It involves VBA

-It will clear the Undo stack/clipboard

-It's potentially more confusing

Workaround

Tag formulae that must be an array formula with a term that has no effect on the outcome. Eg (0*0)+. This term can then be checked and made to always be an array formula through code.

so your formula above becomes {=(0*0)+MATCH(TRUE,(B2:B100}>0,0)}

Then in the THISWORKBOOK

enter this code

Option Explicit

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim cell As Range

For Each cell In Target
    If Target.Cells.Count = 1 Then
        If InStr(1, Target.Formula, "(0*0)+", vbTextCompare) And _
            Target.HasArray = False Then
            Target.FormulaArray = Target.Formula
        End If
    End If
Next cell

End Sub

whenver a cell is changed, the code will check for the term (0*0)+ and assign it as an array formula if it is not one already.




回答2:


There are several ways to convert array formulas into "regular" formulas - that might help you. For example, in this case an added INDEX function means the formula can be entered in the normal way

=MATCH(TRUE,INDEX(B2:B100>0,0),0)



来源:https://stackoverflow.com/questions/12526573/excel-array-formula-not-have-to-ctrl-shift-enter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!