Excel: Error 91: with block and setting worksheet name


Hi forum, I am having a weird problem that I've been struggling for a couple of weeks now. I have a list of employee names in Column A and a a For loop that sets the worksheet name ("wsName") to each cell value (employee names). The macro works fine for the first 13 employees; on the 14th employee, I get Error 91. For whatever reason, on employee 14, it is not setting "wsName". The 14th employee name doesnt have any symbols or numbers.


Dim wsSummary, wsName As Worksheet
Dim sName As String
Set wsSummary = ThisWorkbook.Worksheets("Summary")
With wsSummaryFor i = 1 to 25
        sName = .Range("A" & i).Value
Set wsName = ThisWorkbook.Worksheets(sName)
With wsName
'Some copy and paste stuff
End With
Next i
End With
End Sub
Thanks in advance for your help!


This question generated 15 answers. To proceed to the answers, click here.

This thread is current as of January 29, 2018.


For more resources for Microsoft Excel