Move sheet to the end

DThompson89

New Member
Joined
Dec 15, 2023
Messages
3
Office Version
  1. 2021
Platform
  1. Windows
I'm trying to move a worksheet from one workbook to another and rename it, but I need it at the end of the workbook. I'm calling a user form to select the workbook to move the sheet from and an input box to rename the sheet. Everything is functioning properly except it won't move the sheet to the end. See the code below. It always puts it as the 2nd sheet in the work book. It seems to be counting the sheets in wb1 instead of wb because wb1 is a csv file that always only has one sheet, but if I add a 2nd sheet to the csv file before running the code, it will move the sheet after the 2nd sheet of wb. Is there a way to move to the end other than Sheets.Count?

Sub Move_and_Rename_Sheets()

Dim wb As Workbook
Set wb = ThisWorkbook
Dim wb1 As Workbook

Call Open_Files

Set wb1 = ActiveWorkbook
Dim ws As Worksheet


Dim iName As String
iName = InputBox("Enter the New Name for the Sheet")

If iName <> "" Then
wb1.ActiveSheet.Move After:=wb.Worksheets(Worksheets.Count)
ActiveSheet.Name = iName
End If

End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try:
Rich (BB code):
wb1.ActiveSheet.Move After:=wb.Worksheets(wb.Worksheets.Count)
 
Upvote 0
Solution

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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