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

前端 未结 4 585
一整个雨季
一整个雨季 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:55

    I was able to duplicate your error with the following:

    Sub Test8202Copy()
        Dim wks As Worksheet
        Set wks = Worksheets("Sheet1")
        Dim x As String
    
        For i = 0 To 8202
            x = x + "a"
        Next i
    
        wks.Range("A1").Value = x
        wks.Range("A2") = wks.Range("A1")
    End Sub
    

    I was able to solve the error by adding .value to the copy.

    Sub Test8202Copy()
        Dim wks As Worksheet
        Set wks = Worksheets("Sheet1")
        Dim x As String
    
        For i = 0 To 8202
            x = x + "a"
        Next i
    
        wks.Range("A1").Value = x
        wks.Range("A2").Value = wks.Range("A1").Value
    End Sub
    

    Using an intermediate variable without the use of .Value seems to work:

    Dim y As Variant
    y = wks.Range("A1")
    wks.Range("A2") = y
    

    My guess so far is that 8202 exceed the character limit of the data type used when you don't define .Value. The in cell limit length is 32,767 (MS Excel 2010) which is almost 4x the 8201 value that clears.

提交回复
热议问题