By: Shamima Sultana

In reply to Roland Ocampo.

Hello Roland Ocampo,

Glad you found the macro useful! There shouldn’t be a strict limitation on the number of tabs it can create, but Excel does have a limit on the total number of sheets (which depends on memory). If your macro stops at 20, check if there’s a loop constraint in the VBA code (e.g., a counter limit). You might need to modify the loop to ensure it processes all 45 cells. Also, make sure Excel isn’t restricting macro execution due to settings or available system resources.

Possible Reasons for the Issue:
Error Handling Without Resume Next: The macro might encounter an issue (such as duplicate sheet names or invalid characters) and stop execution without looping through all 45 cells.
Duplicate Sheet Names: If the selected range contains duplicate values, the macro might fail when trying to create a sheet with an existing name.
Invalid Characters in Sheet Names: Excel does not allow certain characters (\ / ? * [ ]) in sheet names, which could prevent some sheets from being created.
Excel Memory or System Limits:

While Excel allows many sheets, system memory might limit the actual number. This version ensures that all 45 sheets are created, handles errors properly, and skips invalid entries instead of stopping the macro.

Sub From_Cell_Range()
'Declare variables
Dim rng As Range
Dim Cell As Range
Dim ws As Worksheet
Dim sheetName As String
Dim errorCount As Integer

'Allow the user to select a range
On Error Resume Next
Set rng = Application.InputBox(Prompt:="Choose Cell Range:", _
Title:="Insert Cell Range", _
Default:=Selection.Address, Type:=8)
On Error GoTo 0

If rng Is Nothing Then Exit Sub 'Exit if no range is selected

errorCount = 0 'Initialize error counter

'Loop through each cell in the selected range
For Each Cell In rng
'Ensure the cell is not empty
If Trim(Cell.Value) <> "" Then
'Extract the sheet name
sheetName = Trim(Cell.Value)

'Ensure the sheet name does not exceed 31 characters
If Len(sheetName) > 31 Then
sheetName = Left(sheetName, 31)
End If

'Check for invalid characters in sheet names
If sheetName Like "*[\/*:?[]]*" Then
errorCount = errorCount + 1
GoTo NextIteration
End If

'Check if a sheet with the same name already exists
Dim sheetExists As Boolean
sheetExists = False
For Each ws In ThisWorkbook.Sheets
If ws.Name = sheetName Then
sheetExists = True
Exit For
End If
Next ws

'Only add the sheet if it does not exist
If Not sheetExists Then
Sheets.Add(After:=Sheets(Sheets.Count)).Name = sheetName
End If
End If

NextIteration:
Next Cell

'Show message if some sheets could not be created
If errorCount > 0 Then
MsgBox errorCount & " sheet(s) could not be created due to invalid names.", vbExclamation, "Warning"
End If

End Sub

Regards
ExcelDemy