How Do I Move/Count specific Sheets using Wildcard Characters?
Dear Forum,
I have to Count and Move only specific Sheet Names whose Sheet Names end in "*Planning"
Can you please help me with a VBA code for the above.
I need to MOve specific Sheets to a New WorkBook which is created Dynamically...
Sub MoveSheets()
Dim FileSpec As String
Dim i As Integer
Dim NewWkb As Workbook
Dim Wks As Worksheet
Dim WksName As String
Dim FolderPath As String
With ThisWorkbook.Worksheets("Replicator")
FileSpec = .Range("C3") ' Folder Path
mkdir(FolderPath)
FileSpec = .Range("C3") ' Path
FileSpec = IIf(Right(FileSpec, 1) <> "\", FileSpec & "\", FileSpec)
FileSpec = FileSpec & .Range("C2") ' Path and the New WorkBook or FileName
ActiveWorkbook.Sheets.Count
For i = 1 To .Range("C4") ' Count the No of Sheets to Be Moved
WksName = .Cells(i + 4, "C")
Set Wks = ThisWorkbook.Worksheets(WksName)
If NewWkb Is Nothing Then
Wks.Move
Set NewWkb = ActiveWorkbook
Else
Wks.Move After:=NewWkb.Worksheets(NewWkb.Worksheets.Count)
End If
Next i
NewWkb.SaveAs FileSpec
NewWkb.Close SaveChanges:=False
End With
End Sub
The above code was provided to me by Leith Ross, I have just added the Folder Option but I want to modify the code further when the FOlder Exists if we can also delete the Folder and the files in the Folder..
Warm Regards
e4excel
Bookmarks