I have an excel workbook where there is continuosly created new worksheets. Sometimes some of the worksheets has to be preserved and ideally deleted from the workbook. The worksheets also needs to be archived in specific folders on SharePoint.
Right now the following VBA does the trick. Nevertheless, it duplicates every cell from the workbook, which I must then relocate to the proper place.
Option Explicit
Sub WorksheetExport()
Dim ws As Worksheet
Dim wsDash As Worksheet
Dim wbToSave As Workbook
Dim filePathToSave As String
Application.ScreenUpdating = False
Set wsDash = Worksheets("LAJ")
filePathToSave = "C:\Test\Example\"
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> wsDash.Name Then
ws.Copy
With ActiveSheet.UsedRange.Cells
.Value = .Value
End With
Set wbToSave = ActiveWorkbook
wbToSave.SaveAs _
Filename:=filePathToSave & wbToSave.Worksheets(1).Name & ".xlsx", _
FileFormat:=51
wbToSave.Close True
End If
Next ws
Application.ScreenUpdating = True
End Sub
If it is possible, I would like to be able to select the precise worksheets to be duplicated or relocated as well as the precise location to which all of the selected worksheets will be transported. Preferably in a dialogue box for user comfort.