Error while copying more than 8202 characters from one cell to another

前端 未结 4 596
一整个雨季
一整个雨季 2020-12-20 19:59

Problem - I have around more than 8202 characters in once cell say Range(\"A1\").

Now I would like to copy the content of cell(A1) to cell(A2) usin

4条回答
  •  渐次进展
    2020-12-20 20:50

    @Chris Neilsen provided the most practical and elegant solution to the problem (his code snippet follows):

    Sheets("XYZ").Range("A2") = Sheets("XYZ").Range("A1").Value
    

    In order to investigate and understand the possible cause of this strange behavior (may be a bug) of the Range object, I've posted couple comments, which are summarized below:

    There is a conceptual difference between the original expression (see below):

    Sheets("XYZ").Range("A2") = Sheets("XYZ").Range("A1")
    

    and solution proposed by @Chris Neilsen, namely: original expression is implicitly assigning the Range object var (essentially, a pointer) to another Range object, like demonstrated in the following code snippet with explicit assignment:

    Set rng = Sheets("XYZ").Range("A1")
    Sheets("XYZ").Range("A2") = rng
    

    while proposed solution explicitly passes the value property. Still, the reason why assigning a Range object failed for a value with string.Length>8202 is currently unclear (it may be caused by some internal nuances of the Excel Range object implementation).

    Many thanks for posting this interesting question and fruitful discussion. Regards,

提交回复
热议问题