Excel VBA: I switched to a new workbook and want to delete a sheet, but code is trying to delete sheet in macro workbook

I am working on a rather large project for a cat rescue. I'm a volunteer and only know enough VBA to be dangerous. I have a spreadsheet that contains all my data. There are several sheets. I've written some code to get the data in order and then to go through the data and pull information for each cat and to create a new workbook that contains a sheet for each cat with the compiled information. I've got down to the last step, and don't know how to accomplish what I am trying to do. When the new workbook is created, it automatically adds a sheet called Sheet1. I add all the new sheets and would like to delete that initial Sheet1 which is blank. When I get to that point in the code by stepping through, I see that the debug shows that it is seeing the sheets in the first workbook that contains the data and the VBA code, and not the new workbook that has all the cat name sheets. I am not sure what I am missing. Here is a little section of the code that I am having issue with.


If (MyFunctions.Sheet_Exists("Sheet1") = True) Then  
    Application.DisplayAlerts = False
    Application.DisplayAlerts = True

End If


Read more here: https://stackoverflow.com/questions/66995411/excel-vba-i-switched-to-a-new-workbook-and-want-to-delete-a-sheet-but-code-is

Content Attribution

This content was originally published by BeckyW at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: