VBA范围255字符限制

时间:2017-08-08 03:31:58

标签: excel vba character-limit

我试图在Excel中创建一个简单的数据库,并且遇到了VBA 255字符限制的错误。我已经创建了几个变量作为String来将正确的输入单元格映射到数据库工作表中的相应列。不幸的是,我正在使用大量变量,因此总字符数超过255:

 myCopy = "D3,D5,D7,A14,B14,C14,D14,E14,G14,H14,I14,J14,K14,L14,M14,N14,O14,P14,R14,S14,T14,R15,S15,T15,R16,S16,T16,R17,S17,T17,U14,V14,W14,X14,Y14,U15,V15,W15,X15,Y15,U16,V16,W16,X16,Y16,U17,V17,W17,X17,Y17,Z14,AA14,AB14,AC14,Z15,AA15,AB15,AC15,Z16,AA16,AB16,AC16,Z17,AA17,AB17,AC17,A1,a1,a1,A1,a1,a1,A1,A1,A1,A1,A1,A1,A1,A1"
myCopy2 = "D3,D5,D7,A18,B18,C18,D18,E18,G18,H18,I18,J18,K18,L18,M18,N18,O18,P18,R18,S18,T18,R19,S19,T19,R20,S20,T20,R21,S21,T21,U18,V18,W18,X18,Y18,U19,V19,W19,X19,Y19,U20,V20,W20,X20,Y20,U21,V21,W21,X21,Y21,Z18,AA18,AB18,AC18,Z19,AA19,AB19,AC19,Z20,AA20,AB20,AC20,Z21,AA21,AB21,AC21,A1,a1,a1,A1,a1,a1,A1,A1,A1,A1,A1,A1,A1,A1"

当我尝试提交数据时,我得到了一个"运行时错误' 1004':方法'范围'对象' _Worksheet'失败"以下行的错误消息:

With inputWks
    Set myRng = .Range(myCopy)
End With

对数据库进行编码,以便在提交完成的输入表单时,每个单元格将进入下一列,每列都是不同的变量(见下文)。因此,我无法删除上面字符串中列出的任何单元格,也无法在正确的位置输入数据。

oCol = 3
    For Each myCell In myRng.Cells
        historyWks.Cells(nextRow, oCol).Value = myCell.Value
        oCol = oCol + 1
    Next myCell

有谁知道如何绕过Range的255个字符限制?

1 个答案:

答案 0 :(得分:1)

您可以尝试这样的事情......

myCopy = "D3,D5,D7,A14:E14,G14:P14,R14:T17,U14:Y17,Z14:AC17,A1"

With inputWks
    Set myRng = .Range(myCopy)
End With

For Each myCell In myRng
    historyWks.Cells(nextRow, oCol).Value = myCell.Value
    oCol = oCol + 1
Next myCell