I have the below VBA Macro to go through a dropdown list of names and then copy and paste the values and formatting for each into a new workbook and then save based on the name. It works well except for the fact that at the end of the process it seems to be hardcoding all of the data in the original workbook as well.
Is there something I can change to prevent this from happening? Below is what I currently have.
Sub CreateWorkbooks()
Dim wb As Workbook
Dim ws As Worksheet
Dim nwb As Workbook
Dim nws As Worksheet
Dim rng As Range
Dim path As String
Dim myDate As String
Dim x As Integer
x = ActiveSheet.Range("C77").Value
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Summary")
Set rng = ws.Range("B2")
path = "X:PrivateForecastForecasts by name"
myDate = Format(Now(), "MM-DD-YYYY")
For i = 77 To x
rng = ws.Range("A" & i)
ws.Copy
Set nwb = ActiveWorkbook
Set nws = nwb.Worksheets("Summary")
With nws
Cells.Copy
Cells.PasteSpecial (xlPasteValues)
End With
Application.DisplayAlerts = False
nwb.SaveAs Filename:=path & rng & " " & myDate & ".xlsx", FileFormat:=xlWorkbookDefault
nwb.Close
Application.DisplayAlerts = True
Next i
End Sub
New contributor
darthdepression is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.