0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Excel VBAで 255文字超の 配列数式 FormulaArrayを設定する

Posted at

配列数式は255文字までしか設定できません。

配列数式は FormulaArrayプロパティで設定できますが、VBAからは255文字までしか設定できません。
Ctrl + Shift + Enterで手で設定する場合は、そのような制限はないのですが、VBAから設定する場合は、そのような制限があります。
どうしようもないので、どうしても設定した場合、SendKeysを使って、手で設定したことにするという苦しい逃げ道があります。

sample.txt

Sub SetTooLongArrayFormula(ByVal rn As Range, ByVal sFormula As String)
    Dim sFormat As String
    sFormat = rn.Cells(1, 1).NumberFormat
    rn.FormulaArray = ""
    rn.Cells(1, 1).NumberFormat = "@"
    rn.Value = sFormula
    rn.Cells(1, 1).NumberFormat = sFormat
    rn.Select
    DoEvents
    SendKeys "{F2}", True 'F2で式を編集モードにします。
    DoEvents
    SendKeys "+^{ENTER}", True 'Ctrl+Shift+Enterを押します。
    
End Sub
Sub Test()
    'このマクロをVBE Editorから実行しないでください。
    'リボンの開発タブのマクロリボンから実行してください。
    Dim sFormula As String
    sFormula = "=""1"""
    For i = 1 To 250
        sFormula = sFormula & "&""1"""
    Next
    SetTooLongArrayFormula Range("A1:A2"), sFormula
End Sub

この投稿は、
https://akihitoyamashiro.blogspot.com/2020/07/how-to-set-formulaarray-property-to.html
に記載したものと同じ内容です。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?