moving sheet and keep activating one

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,640
Office Version
  1. 365
Platform
  1. Windows
Hi
I have 3 sheets named 1,2,3 and I am moving them around using the code below. sheet name "2" has the button which run the code. I want to do the move but keep going back to sheet("2"). I did it as below. How you would do it yourself? Is that good and efficient programming? Thank you so much

Code:
Sub movesheet()
    Dim x As Integer
    Dim y As Integer
    x = InputBox("sheet to move")
    y = InputBox("after which sheet")
    Workbooks(1).Worksheets(x).Move after:=Worksheets(y)
    Workbooks(1).Worksheets("2").Activate
End Sub
 

Some videos you may like

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
19,751
Office Version
  1. 2016
  2. 2013
  3. 2007
Platform
  1. Windows
I'd go this way...


Code:
Sub movesheet()
Dim x As Integer, y As Integer
x = InputBox("sheet to move")
y = InputBox("after which sheet")
    With Worksheets(x)
        .Move after:=Worksheets(y)
    End With
End Sub
 

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,640
Office Version
  1. 365
Platform
  1. Windows
Thank you very much for your reply and help but after I run that code, sheet2 will not be the active one. Thank you
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
13,850
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
The added sheet will always be the activesheet until you activate the sheet you want (which you have done). What is your issue?
 

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,640
Office Version
  1. 365
Platform
  1. Windows
Ok thank you very much. Just wanted to make sure. Thanks alot.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,737
Messages
5,597,826
Members
414,180
Latest member
Sir Khaya

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
Top