不匹配错误,不应该是

时间:2017-08-01 01:22:22

标签: vba excel-vba excel

我正在尝试编写一个宏,但它目前正在返回"不匹配错误"。

当我拿出" ListSheets = SheetName"部分,它工作正常,但当然不会输出我要找的东西。

我不理解错误,因为问题代码行的两边都应该是字符串。

Function ListSheets() As String

Dim i As Integer
Dim k As Integer
Dim sRow As Integer
Dim mNum As Integer
Dim sName() As String
Dim SheetName() As String
Dim Width As Integer
Width = 8


'initialize sheet name list
sRow = LastRow("Category List", 1)
mNum = Cells(sRow, 1)

ReDim sName(1, sRow)
ReDim SheetName(mNum)

'copy sheet list
For i = 2 To sRow
    sName(0, i) = Cells(i, 1)
    sName(1, i) = Cells(i, 1) & " - " & Cells(i, 2)
Next i

'transform list to good list
k = 2
For i = 1 To mNum
    If IsNumeric(sName(0, k)) Then
        If i = sName(0, k) Then
            SheetName(i) = sName(1, k)
            k = k + 1
        End If
    End If

    If i = 100 Then
        k = k + 2
    ElseIf i = 200 Then
        k = k + 2
    ElseIf i = 500 Then
        k = k + 2
    End If

Next i

ListSheets = SheetName

End Function

1 个答案:

答案 0 :(得分:2)

将返回类型更改为String()而不是String。