moving sheet and keep activating one

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
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
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
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
 
Upvote 0
Thank you very much for your reply and help but after I run that code, sheet2 will not be the active one. Thank you
 
Upvote 0
The added sheet will always be the activesheet until you activate the sheet you want (which you have done). What is your issue?
 
Upvote 0
Ok thank you very much. Just wanted to make sure. Thanks alot.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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