Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using Sheets.Add from a UserForm the new sheet is "connected" to another sheet?

Tags:

excel

vba

I'm having a problem when adding new sheets to a Workbook from a UserForm. Basically whenever I add a new sheet, it appears to be linked to another sheet in the same workbook.

I have been able to reproduce this issue fairly easily by creating a new Excel file, then adding it a new userform with this code in it:

Private Sub UserForm_Click()
    Sheets.Add
    Call Unload(Me)
End Sub

If I open the userform from a sheet such as this one:

enter image description here

And then I double click the userform, the issue already happens.

The new sheet is works incorrectly. For example if I write on any cell of the new sheet I get the formatting from the original sheet. Worse still, if the original sheet is protected, I'm not allowed to write on the new sheet (though the ribbon shows it's unprotected).

enter image description here

If I select another sheet and select the new sheet again everything returns to normal. Am I doing something wrong? If it's a bug is there any workaround?

Here is an Excel file that produces the error: Drive.google.com

like image 589
lisovaccaro Avatar asked Mar 01 '16 18:03

lisovaccaro


1 Answers

In Userform1's properties, change the ShowModal to False.

I was able to re-produce the behavior. I changed the ShowModal to False and the behavior changed to the expected behavior. I made no changes to any VBA code.

I'm running 64-bit Excel 2013 from MS Office Professional.

like image 78
B540Glenn Avatar answered Sep 21 '22 08:09

B540Glenn