Is there equivalent vba code for Excel 2013?

Lidsavr

Active Member
Joined
Jan 10, 2008
Messages
330
I just started running Excel 2013 and some of the vba code that I used for Excel 2010 isn't working. I get a "Subscript out of range" error when stepping through the code. The line reads:

Code:
Sheets(2).Select

Is there an Excel 2013 equivalent for this line of code (I don't want to use the sheet name)?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Andrew,
Thank you for replying. There are two sheets in the workbook. The line prior is:

Code:
Sheets.Add After:=ActiveSheet

The workbook starts out with one sheet and the above code adds another. I then want to select the first sheet (left side of the workbook). Because the new sheet is active once it is added, I want to select the original sheet, which name is different depending on the month. Here is the code that I have up to the error (which is only in Excel 2013; it runs fine in Excel 2010):

Code:
Sheets.Add After:=ActiveSheet
Sheets(2).Select

Any idea what (if anything) I am doing wrong?
 
Upvote 0
Avoid any 'select' or 'activate'
Use instead:

Code:
With Sheets.Add(, activesheet)
    .name="new sheet"
 '  your other code
end with
 
Upvote 0

Forum statistics

Threads
1,226,237
Messages
6,189,790
Members
453,568
Latest member
LaTwiglet85

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top