Hello all,
I have a macro that copies any tabs are not named "EnterNames" or "Details" and creates a new excel file with them.
I'm trying to delete those tabs from the original file after they are moved over.
I tried doing so with this line:
It worked but excel crashes when I try to close or save afterwords. I don't get any error, it simply crashes.
The macro works great before I add that one line. I was inserting the delete line after this line:
Is there a way to make it not crash? Also, when I had the delete line, excel asks: "Data may exist in the sheet(s) selected for deletion. To permanently delete the data press delete."
Is there a way to get rid of that warning message?
Here's the entire macro:
Thanks in advance!
I have a macro that copies any tabs are not named "EnterNames" or "Details" and creates a new excel file with them.
I'm trying to delete those tabs from the original file after they are moved over.
I tried doing so with this line:
Code:
ThisWorkbook.Worksheets(strMyArray).Delete
The macro works great before I add that one line. I was inserting the delete line after this line:
Code:
ThisWorkbook.Worksheets(strMyArray).Copy
Is there a way to make it not crash? Also, when I had the delete line, excel asks: "Data may exist in the sheet(s) selected for deletion. To permanently delete the data press delete."
Is there a way to get rid of that warning message?
Here's the entire macro:
Code:
Sub MoveWorksheets()
Dim strMyArray() As String
Dim intArrayCount As Integer
Dim wstMySheet As Worksheet
intArrayCount = 0
Application.ScreenUpdating = False
For Each wstMySheet In ThisWorkbook.Worksheets
If wstMySheet.Name <> "EnterNames" And wstMySheet.Name <> "Details" Then
intArrayCount = intArrayCount + 1
ReDim Preserve strMyArray(1 To intArrayCount) 'Copy elements from the existing array to the new array
strMyArray(intArrayCount) = wstMySheet.Name
End If
Next
ThisWorkbook.Worksheets(strMyArray).Copy
Erase strMyArray() 'Deletes the variable contents to free some memory
Application.ScreenUpdating = True
End Sub
Thanks in advance!
Last edited: