I'm trying to figure out a way to loop through a variable row of data and create Worksheet names based on the cell. The issue I'm having is that each cell has the following two issues:
- They have invalid '/' characters that I would like to replace with a blank space ' ' i.e. 5000111/01/18 - ideally this would be changed to worksheet tab '01 18 SICS'
- There will be duplicate cells with the same cell reference and I only want one worksheet
Here is my code that I have so far
Sub Format()
Dim lastRow As Long
Dim sheetName As String
Dim workbookCount As Long
Dim ws As Worksheet
Dim match As Boolean
'Turn off Screen updating
Application.ScreenUpdating = False
'Rename Sheet1 as AR
Worksheets("Sheet1").Name = "AR"
lastRow = Sheets("AR").Range("A2").End(xlDown).Row
For i = 2 To lastRow
match = False
sheetName = Sheets("AR").Cells(i, 1).Text
For Each ws In ActiveWorkbook.Worksheets
If ws.Name = sheetName Then
match = True
End If
Next
If match = False Then
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = sheetName
End If
Next i
'Turn on Screen Updating
Application.ScreenUpdating = True
End Sub
I get an error when i get to the last bit of code .Name =sheetName because it contains the '/' invalid character.