Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel 2013 worksheet activate

I have an issue with activating a sheet from a user form, the same code works fine in Excel 2003 to Excel 2010, doesn't work with Excel 2013.

This is how to simply reproduce the issue:

Have a workbook with 2 worksheets in it, called Sheet1 and Sheet2 let's say, and on Sheet1 2 buttons:

  1. On click of Button1 activates Sheet2 worksheet using a Macro1 with 1 line in it:

    ThisWorkbook.Sheets("Sheet2").Select
    

    and I can edit data from it fine.

  2. On click of Button2 a UserForm1 pops up and on click of CommandButton1 call same Macro1 like this:

    Unload Me
    Macro1
    

    the Sheet2 worksheet is activated, sort of, but if I edit data in it, it actually updates corresponding cells in Sheet1, if I click on Sheet1 I can see data entered in there!

Clicking back to Sheet2 worksheet activates the Sheet2 sheet properly.

Has anyone seen such behaviour? If yes, are there any coding workarounds to properly activate Sheet2?

like image 867
user2766088 Avatar asked Sep 10 '13 18:09

user2766088


People also ask

How do you activate a worksheet in Excel?

By keyboard: First, press F6 to activate the sheet tabs. Next, use the left or right arrow keys to select the sheet you want, then you can use Ctrl+Space to select that sheet.

What does it mean to activate a worksheet in Excel?

VBA Activate Worksheet method is used to makes the current sheet as active sheet. Here we are the examples using Activate method of worksheet object in VBA. It is very frequently used method while writing VBA macros.

How do I activate my Excel window?

You can do this by selecting the cell that contains the text and press CTRL+K then select the option/tab 'Place in this document' and select the tab you want to activate. If you would click the text (that is now a link) the configured sheet will become active/selected.


1 Answers

Wow, I was able to reproduce this error using 2013. This is a fantastic failure of Excel's new SDI Interface. What is also interestingly odd is that when you follow the following steps

  • Select cell A1 on Sheet1
  • Select cell B2 on Sheet2
  • Click Button2 which opens the form
  • Click the CommandButton1 on the form (which hides the form and activates Sheet2)

it looks like cell B2 on Sheet2 is selected, but when you start typing, the text is going into cell A1; Once you hit Enter the text disappears to cell B2 on Sheet1

You almost have to see it to believe it.

The only thing that I've found that works is using the Ontime function.

Private Sub CommandButton1_Click()
    Unload Me
    'Call Macro1
    Application.OnTime Now(), "Macro1"
End Sub

...but I have a feeling that this isn't going to help everyone

like image 62
Profex Avatar answered Sep 28 '22 23:09

Profex