title: Excel Add Sheet or Overwrite if Exists
body: <p>In excel I have a macro that converts all of columns of an active sheet into an new sheet called "MasterList"</p>
  
  <p>My problem is when I rerun that macro I get an error saying "That name is already taken." Try a different one. </p>
  
  <p>I need my macro to overwrite MaterList sheet if it already exists.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>Sub ToArrayAndBack()
  Dim arr As Variant, lLoop1 As Long, lLoop2 As Long
  Dim arr2 As Variant, lIndex As Long
  
  'turn off updates to speed up code execution
  With Application
      .ScreenUpdating = False
      .EnableEvents = False
      .Calculation = xlCalculationManual
      .DisplayAlerts = False
  End With
  
  
  ReDim arr2(ActiveSheet.UsedRange.Cells.Count - ActiveSheet.UsedRange.SpecialCells(xlCellTypeBlanks).Count)
  
  arr = ActiveSheet.UsedRange.Value
  
  
  For lLoop1 = LBound(arr, 1) To UBound(arr, 1)
      For lLoop2 = LBound(arr, 2) To UBound(arr, 2)
          If Len(Trim(arr(lLoop1, lLoop2))) &gt; 0 Then
              arr2(lIndex) = arr(lLoop1, lLoop2)
              lIndex = lIndex + 1
          End If
      Next
  Next
  
  Sheets.Add.Name = "MasterList"
  
  Range("A1").Resize(, lIndex + 1).Value = arr2
  
  Range("A1").Resize(, lIndex + 1).Copy
  Range("A2").Resize(lIndex + 1).PasteSpecial Transpose:=True
  Rows(1).Delete
  
  With Application
      .ScreenUpdating = True
      .EnableEvents = True
      .Calculation = xlCalculationAutomatic
      .DisplayAlerts = True
  End With
  
  
  End Sub
  </code></pre>