I have a macro to create a new worksheet and rename that sheet with hyperlink based on the value of cell in the "Master" sheet range("A5").
It will stop at a blank cell. What should I add to skip the blank cell and continue?
Function CheckSheetExists(ByVal name As String)
' checks if a worksheet already exists
Dim retVal As Boolean
retVal = False
For s = 1 To Sheets.Count
If Sheets(s).name = name Then
retVal = True
Exit For
End If
Next s
CheckSheetExists = retVal
End Function
Sub AutoAddSheet()
Dim MyCell As Range, MyRange As Range
Set MyRange = Sheets("Master").Range("A5")
Set MyRange = Range(MyRange, MyRange.End(xlDown))
For Each MyCell In MyRange
On Error Resume Next
If CheckSheetExists(MyCell.Value) = False Then
Sheets("Template").Copy After:=Sheets(Sheets.Count)
With Sheets(Sheets.Count)
.name = MyCell.Value
.Cells(3, 1) = MyCell.Value
End With
End If
On Error GoTo 0
MyCell.Hyperlinks.Add Anchor:=MyCell, Address:="", SubAddress:="'" & MyCell.Value & "'!A1"
Next MyCell
End Sub