Hi, I wonder whether someone may be able to help me please.
I'm using the code below to search column B on the "All Data" sheet, and where a unique value is found create a new sheet and use the value from column B as the sheet name.
Sub AddSheets()
Application.ScreenUpdating = False
Dim bottomA As Integer
Dim i As Long 'counter variable
Dim rng As Range
Dim shArray() As Variant 'Declare the sheet Name array
Dim ws As Worksheet
Set ws = Sheets("All Data")
ws.Select
bottomB = Range("B" & Rows.Count).End(xlUp).Row
For Each rng In Range("B8:B" & bottomB)
If rng <> rng.Offset(1, 0) Then
Set ws = Nothing
On Error Resume Next
Set ws = Worksheets(rng.Value)
On Error GoTo 0
If ws Is Nothing Then
Worksheets.Add(After:=Sheets(Sheets.Count)).Name = rng.Value
End If
End If
Next rng
End Sub
The question I have is could someone perhaps tell me please how I can assign a variable to create an array when the new sheets are created.
I'm assuming that the change is needed here, Worksheets.Add(After:=Sheets(Sheets.Count)).Name = rng.Value but I may very well be wrong.
Many thanks and kind regards
Chris
Bookmarks