错误不匹配VBA

时间:2018-02-22 14:23:04

标签: excel windows vba excel-vba

enter image description here我很难弄清楚代码中发生了什么。它一直在说"运行时错误:' 13' &#34 ;.我该如何处理这个错误?

Dim ws As Worksheet
Dim rearr(), wrarr()
Dim fName As String
Dim rowno As Long, colno As Long, rec As Long
Dim cnt As Long, cnt2 As Long
Dim delim As String

'specify output sheet
Set ws = Worksheets("1.Locations")
'specify text file to read (.csv in this example)
fName = "C:\Users\HP\Desktop\names.csv"
'set text file delimiter
delim = "," 'for Tab delimiter use delim = Chr(9)
ifnum = FreeFile
'set start row/col for text data to be placed ("A1" in this example)
rowno = 3  'row 1
colno = 2  'col A

    With ws
        Open fName For Input Access Read As #ifnum
            rec = 0
                Do While Not EOF(ifnum)
                    Line Input #ifnum, tmpvar
                    rec = rec + 1
                    'Put whole record into array
                    ReDim Preserve rearr(1 To rec)
                    rearr(rec) = tmpvar
                    'Split fields into a second array
                    wrarr = Split(rearr(rec), delim)
                    cnt2 = UBound(wrarr)
                        'Write fields out to specified ws range, one row per record
                        For cnt = 0 To cnt2
                            ws.Cells(rowno, colno + cnt) = wrarr(cnt)
                        Next cnt
                     rowno = rowno + 1
                Loop
            Close #ifnum
    End With

1 个答案:

答案 0 :(得分:0)

我已经复制了你的错误。

在您的声明中,更改

Dim wrarr

{{1}}