2

Excel の明らかな 255 文字制限に関連する一般的な問題に取り組んでいます。関数からバリアント配列をワークシートの選択範囲に返そうとすると、エラーが発生します。関数が返す配列内の各セルが 255 文字未満の場合、必要に応じてシートに投稿されます。選択した範囲内の各セルに 1 つの要素が表示されます。ただし、返されるバリアント配列のいずれかの要素が 255 文字を超える場合は、値を取得します! エラー。長い要素が必要で、データをまとめたいので、これらのエラーは悪いです!

この問題のバージョンは多くのフォーラムで何度も何度も出てきますが、配列セルが 255 文字を超えた場合に、バリアント配列を選択した範囲 (必ずしも数式を含む必要はありません) に戻すための明確でシンプルな汎用ソリューションを見つけることができます。私の最大の要素は約 1000 ですが、ソリューションが最大 2000 文字の要素に対応できればより良いでしょう。

できれば、これを関数、または関数(サブルーチンではなく)に追加できる追加コードの行で実装したいと考えています。サブルーチンを避けたい理由: 範囲をハードコードする必要はありません。これを柔軟にし、現在の選択に基づいて出力場所を動的に変更したいと考えています。

Variant Array を入力として取り、目的の array:cell 1:1 の関係を維持する関数を作成する方法を見つけるのを手伝っていただければ幸いです。

したがって、短いセルを使用したこの関数は機能します。

Function WriteUnder255Cells()

Dim myArray(3) As Variant  'this the variant array I will attempt to write

' Here I fill each element with less than 255 characters
' it should output them if you call the function properly.
myArray(0) = "dog"
myArray(1) = "cat"
myArray(2) = "bird"
myArray(3) = "fly"

WriteUnder255Cells = Application.Transpose(myArray())

End Function

ただし、この関数は、255 を超えるセルでは出力されません。

Function WriteOver255Cells()

Dim myArray(3) As Variant  'this the variant array I will attempt to write

' Here I fill each element with more than 255 characters
' exceeding the 255-character limit causes the VALUE! errors when you output them
myArray(0) = "ThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelaxydog"
myArray(1) = "ThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydog"
myArray(2) = "ThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydog"
myArray(3) = "ThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydogThequickbrownfoxjumpedoverthelazydog"

WriteOver255Cells = Application.Transpose(myArray())

End Function

これは、出力と結果を生成する方法です。

最初に、2 つのモジュールを作成する必要があります (各モジュールに 1 つの関数を挿入するには、1 つのコードをそれぞれのモジュールに貼り付けます)。「WriteUnder255Cells()」を実行するには、シートの 4 行 x 1 列の領域 (モジュールを返す場所) を選択し、数式バーに「=WriteUnder255Cells()」と入力します (引用符は入力しないでください)。これらは配列数式のように呼び出されるため、 (enter) を押して出力を作成する代わりに、(control + shift + enter) を押す必要があることに注意してください。WriteOver255Cells() に対して同じプロセスを繰り返して、エラーを生成します。

これに対処するいくつかのドキュメント/フォーラムの議論があります。解決策は、サブルーチンを呼び起こすため、過度に具体的または不格好なようです (これは避けたいと思います)。

https://support.microsoft.com/en-us/kb/213841

http://www.mrexcel.com/forum/excel-questions/852781-visual-basic-applications-evaluate-method-255-character-limit.html

Excel: 255 文字を超える数式を使用してください

配列値が 255 文字を超えると VBA コード エラーが発生する

http://dailydoseofexcel.com/archives/2005/01/10/entering-long-array-formulas-in-vba/

https://forums.techguy.org/threads/solved-vba-access-to-excel-255-char-limit-issue.996495/

http://www.mrexcel.com/forum/excel-questions/494675-255-character-cell-limit-visual-basic-applications-workaround.html

255 文字を超える配列数式

http://www.mrexcel.com/forum/excel-questions/388250-size-limit-transferring-variant-range-excel-2007-a.html

4

1 に答える 1

4

これは私のために働く:

Function Over255()

    Dim myArray(3)  As String '<<<<< not variant

    myArray(0) = String(300, "a")
    myArray(1) = String(300, "b")
    myArray(2) = String(300, "c")
    myArray(3) = String(300, "d")

    'Over255 = Application.Transpose(myArray())
    Over255 = TR(myArray)

End Function

'like Application.Transpose...
Function TR(arrIn) As String()
    Dim arrOut() As String, r As Long, ln As Long, i As Long

    ln = (UBound(arrIn) - LBound(arrIn)) + 1
    ReDim arrOut(1 To ln, 1 To 1)
    i = 1
    For r = LBound(arrIn) To UBound(arrIn)
        arrOut(i, 1) = arrIn(r)
        i = i + 1
    Next r
    TR = arrOut

End Function

文字列配列を返す必要があるようですが、Application.Transposeそうしません

于 2016-02-15T00:24:56.567 に答える