Moving A Worksheet To The End of all Existing Worksheets

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,570
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.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Change the first line to

Code:
With Sheets("ws_src")
 
Upvote 0
The code works for me.
It sends you an error, what does the error say, on which line does it stop?
 
Upvote 0
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")
 
Upvote 0
You have hidden sheets, protected sheets, how many sheets do you have when you try the process?
 
Upvote 0
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 ??
 
Upvote 0
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)
 
Upvote 0
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:
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