Moving A Worksheet To The End of all Existing Worksheets

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
3,812
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am not having any luck with moving a worksheet to after the last worksheet in the workbook.

Rich (BB code):
              With ws_src
                    ag = 365
                    .Unprotect
                    dt_row = Application.WorksheetFunction.Match(CLng(Date), .Columns(2), 0)
                    .Range("C" & dt_row & ":G" & ag).ClearContents
                    .Protect
                    .Name = "(former " & tab_scr & ")"
                    .Tab.Color = RGB(33, 54, 51)
                    .Move after:=Worksheets(Worksheets.Count)
                    .Visible = False
                End With

I am trying to move worksheet ws_src to the last worksheet of the workbook. It's not working.
 

Some videos you may like

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
19,767
Office Version
  1. 2016
  2. 2013
  3. 2007
Platform
  1. Windows
Change the first line to

Code:
With Sheets("ws_src")
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,594
Office Version
  1. 2007
Platform
  1. Windows
The code works for me.
It sends you an error, what does the error say, on which line does it stop?
 

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
3,812
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
No errors, it just doesn't send the sheet to the end.
Michael, ws_src is an alias ...

Code:
dim ws_src as worksheets
set ws_src = worksheets("source")
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,594
Office Version
  1. 2007
Platform
  1. Windows

ADVERTISEMENT

You have hidden sheets, protected sheets, how many sheets do you have when you try the process?
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
19,767
Office Version
  1. 2016
  2. 2013
  3. 2007
Platform
  1. Windows
The original code worked for me as well, but you didn't advise that you had set the sheet variable.
Have you tried it without the protection ?
Is the workbook protected in the code as well ??
 

Fazza

MrExcel MVP
Joined
May 17, 2006
Messages
9,368
if the code is in a different file from the workbook with the worksheets, add a workbook reference?

something like
.Move after:=workbookreference.Worksheets(workbookreference.Worksheets.Count)
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,594
Office Version
  1. 2007
Platform
  1. Windows
There are so many questions because we can not see how you have your book, if you provide us with more information about the environment of your book, we can look for a solution.


Try moving a sheet, in a new book, to rule out vba or version problems.

eg.
Code:
Sub tomove()
    Sheets("Sheet1").move after:=Worksheets(Worksheets.Count)
End Sub
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,123,400
Messages
5,601,462
Members
414,451
Latest member
jrose7

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