标识符太长了

时间:2015-02-04 02:09:25

标签: excel vba excel-vba

我遇到了这个问题:“标识符太长”。我该怎么做才能解决这个问题?我尝试使用中断“_”。但是会出现另一个错误:缺少结束括号。谢谢你们。

 Sub Netting()

     Dim Found As Range
     Dim LR As Long
     Dim ws As Worksheet
     Dim cell As Range
     Dim a As Variant, v As Variant, num

     Set ws = Sheets("PAYABLES - OUTFLOWS")

     Set Found = ws.Rows(1).Find(What:="Invoice Amount", _
                                LookIn:=xlValues, lookat:=xlWhole)
     If Found Is Nothing Then Exit Sub

     a = [{"991",1042;"916", 1042;"954",261;"975",3004;"938",726;"901",762;"482",728; _
            "482",728;"934",723;"200",724;"201",724;"952",724;"992",3030;"980",3207;"116",626;"939",722;"390",517;"484",548;"339",59;"141",717;"935",59;"994",3370;"140",8408;"950",775;"370", 734 }] 'create 2-d lookup array

     LR = ws.Cells(ws.Rows.Count, Found.Column).End(xlUp).Row
     Found.Offset(0, 1).EntireColumn.Insert
     ws.Cells(1, Found.Column + 1).Value = "Netting"

     For Each cell In ws.Range(ws.Range("C2"), ws.Cells(LR, 3))
        num = CStr(Mid(cell.Value, 3, 3))
        v = Application.VLookup(num, a, 2, False)
        cell.EntireRow.Cells(Found.Column + 1).Value = IIf(IsError(v), "", v)
     Next cell

End Sub

1 个答案:

答案 0 :(得分:1)

每行的字符数有限制。您可以使用更简单的方法完成此操作。将您的数据添加到电子表格(例如“Sheet1”)以及A列和B列。

Sub Assign2DVector()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    Dim a As Variant
    a = ws.Range("A1:B20").Value ' set to whatever your actual range is
End Sub