Saturday, 12 December 2020

How to Move Sheets in Excel VBA



In this blog post, you will learn about how to move sheets “before” and “after” any particular sheet in Excel by VBA.


Here in the below image, you can see that there are multiple sheets inserted. Here we will move any sheet before and after to other sheets.

Now we will use these sheets to move from one place to another.




Move Sheet After Another


First of all, we will move the sheet My Data to after sheet Main.

Use the code below:-


“Sub Move_Sheet_Name()

Sheets("My Data").Move after:=Sheets("Main")

End Sub”


Write the above VBA code in a new module and execute the code by pressing “F8” again and again until End Sub.


See the below image, where we have successfully moved the sheet “My Data” from its place to after sheet Main.





Move Sheet Before Another

Now with the help of VBA macro, we will move sheet “New Data” before sheet Main.

Use the below VBA code.


“Sub Move_Sheet_Before()

Sheets("New Data").Move before:=Sheets("Main")

End Sub”



See the result in the below image:-




So in this blog post, you learned about how to move a sheet before or after any particular sheet.

I hope you find this blog post useful.

Please feel free to put your comments and suggestion in the below comment box.


Thanks

Narendra


Related Post

How to Insert a New Sheet In Excel VBA

What is Current Region Property in VBA

How to use Orientation in Excel VBA

Easiest Way to Copy and Paste Data in Excel VBA

How to Change the Background Color in Excel VBA

How to Change Font Color in Excel VBA

How to Change or Rename the Sheet Name in Excel VBA





No comments:

Post a Comment

Featured post

Pivot Tables