This commit is contained in:
2025-08-05 07:35:48 -05:00
parent 26ac61021a
commit 435ffe1478
9 changed files with 1472 additions and 1 deletions

50
createSheets.bas Normal file
View File

@@ -0,0 +1,50 @@
Attribute VB_Name = "createSheets"
Sub CreateSheetIfNotExist()
Dim cellValue As String
Dim sheetNames As Variant
Dim i As Long
Dim ws As Worksheet
Dim sheetExists As Boolean
' Articles seperated by a ,
cellValue = ThisWorkbook.Sheets("Setup Data").Range("B24").Value
' Split the comma-separated string into an array of sheet names
sheetNames = Split(cellValue, ",")
Debug.Print "Value in the cell: " & cellValue
' Split the comma-separated string into an array of sheet names
sheetNames = Split(cellValue, ",")
Debug.Print "Result of Split function:"
For i = LBound(sheetNames) To UBound(sheetNames)
Debug.Print " Index " & i & ": """ & sheetNames(i) & """"
Next i
' Loop through each potential sheet name
For i = LBound(sheetNames) To UBound(sheetNames)
Dim newSheetName As String
newSheetName = Trim(sheetNames(i)) ' Remove any leading/trailing spaces
sheetExists = False
' Check if the sheet already exists
For Each ws In ThisWorkbook.Sheets
If ws.Name = newSheetName Then
sheetExists = True
Exit For
End If
Next ws
' If the sheet doesn't exist, create it
If Not sheetExists Then
On Error Resume Next ' In case there's an issue creating the sheet
ThisWorkbook.Sheets.Add After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
ActiveSheet.Name = newSheetName
On Error GoTo 0 ' Resume normal error handling
Debug.Print "Sheet '" & newSheetName & "' created."
Else
Debug.Print "Sheet '" & newSheetName & "' already exists."
End If
Next i
End Sub