ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Activate Previous worksheet after adding a new worksheet (https://www.excelbanter.com/excel-programming/343184-activate-previous-worksheet-after-adding-new-worksheet.html)

[email protected]

Activate Previous worksheet after adding a new worksheet
 
I want to activate the worksheet that was active before I added a new
sheet to the workbook in VBA for excel. Can anyone help me on how to do
that?


Dave Peterson

Activate Previous worksheet after adding a new worksheet
 
dim mySelection as range
set myselection = selection
'add your worksheet
application.goto myselection



wrote:

I want to activate the worksheet that was active before I added a new
sheet to the workbook in VBA for excel. Can anyone help me on how to do
that?


--

Dave Peterson

JakeyC

Activate Previous worksheet after adding a new worksheet
 
Not sure if this post worked so apologies if this is a duplicate:

Option Explicit

Sub ()
Dim CurrentSheet, NewSheet As Worksheet

Set CurrentSheet = ActiveSheet
Set NewSheet = Worksheets.Add

CurrentSheet.Activate
End Sub


JakeyC

Activate Previous worksheet after adding a new worksheet
 
I think this should work:

Option Explicit

Sub ()
Dim CurrentSheet, NewSheet As Worksheet

Set CurrentSheet = ActiveSheet
Set NewSheet = Worksheets.Add

CurrentSheet.Activate
End Sub



All times are GMT +1. The time now is 03:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com