title: Use Excel VBA to copy a worksheet into a new workbook and make changes to the new workbook
body: <p>Apologies in advance if this is a duplicated post - I searched for quite a while and couldn't find anything to solve my issue. I have an excel spreadsheet that I would like to duplicate into a new workbook, and then perform some functionality on the new workbook to remove various portions of the copied content while leaving the original unaltered. </p>
  
  <p>I have the code working that will copy the sheet into a new workbook and save it, which is shown below:</p>
  
  <pre><code>Dim strFileName As String
  
  'Copy sheet as a new workbook
  Sheets("Sheet1").Copy
  
  'SaveAs
  strFileName = Application.GetSaveAsFilename(ActiveWorkbook.Name) &amp; "xlsx"
  If strFileName = "False" Then Exit Sub 'User Canceled
  ActiveWorkbook.SaveAs Filename:=strFileName
  </code></pre>
  
  <p>My issue is in where to put the code that I'd like to use after the new workbook is created, and whether I need to put more code specifying which workbook or worksheet I'd like to perform the functionality in (maybe a .Activate or a .open?). Below is what code I've written to remove what data I don't want, which works fine if I run it inside the original worksheet rather than the duplicated copy:</p>
  
  <pre><code>'removes rows when criteria is met
  x = 4
  Do While Sheet1.Cells(x, 1).Value &lt;&gt; ""
      If (Sheet1.Cells(x, 1) = "Prospect") Or (Sheet1.Cells(x, 1) = "Lead") Then
      Sheet1.Rows(x).Delete
      Else
      x = x + 1
      End If
  Loop
  
  'removes rows when criteria is met
  y = 4
  Do While Sheet1.Cells(y, 5).Value &lt;&gt; ""
      If (Sheet1.Cells(y, 5) = "Non-exclusive") Then
      Sheet1.Rows(y).Delete
      Else
      y = y + 1
      End If
  Loop
  
  'removes columns
  Sheet1.Columns("P:S").Delete
  Sheet1.Columns("F").Delete
  </code></pre>
  
  <p>So in short how do I get this code working on the sheet I just created? Any help would be very much appreciated, and if I did not clarify something please feel free to ask!</p>