daniel brandstetter
daniel brandstetter

Reputation: 160

Mismatch Error where there shouldn't be

I am trying to write a macro, but it's currently returning "mismatch error".

When I take out the "ListSheets = SheetName" part, it works fine, but of course doesn't output what I am looking for.

I don't understand the error, because both sides of the problem line of code should both be strings.

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

Upvotes: 0

Views: 29

Answers (1)

JG7
JG7

Reputation: 371

Change your return type to String() instead of String.

Upvotes: 2

Related Questions