Move sheet

kizmet311

New Member
Joined
Sep 7, 2018
Messages
8
I am trying to move a sheet from activeworkbook to a file that is stored in a folder. Any help is greatly appreciated, I have attached the code that i am currently trying to use. I feel that i am over thinking this.

Sub move_sheet()


'Move the active sheet to the end of named Workbook.
'Replace filepath with the full name of the target workbook you want.

Dim filepath As String

filepath = "C:\Users\Nick.Clark\Desktop\Compare.xlsx"

ActiveWorkbook.ActiveSheet.Move After:=Workbooks(filepath).Sheets(Sheets.Count)


End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi there. Doesnt look to be wrong - do you get any error message?
 
Last edited:
Upvote 0
I tried with both files open and still no luck. I am getting "Run-time error '9': Subscript out of range".
 
Upvote 0
Ok OK try this change:
Code:
ActiveWorkbook.ActiveSheet.Move After:=Workbooks(filepath).Sheets(Workbooks(filepath).Sheets.Count)
 
Upvote 0
Sorry, I will think on and try it myself later - hopefully someone else on the forum can help further.
 
Upvote 0
Is the other workbook open?
 
Upvote 0
I have tried this with the both workbooks open and with only the one i am moving the sheet from. If there is a different way to do this I am open. I can keep the destination file constant, but the one file will change. I appreciate the help. I am fairly new to VBA, working to automate processes for beginner excel users.
 
Upvote 0
How about
Code:
Sub kizmet311()
   Dim FilePath As String
   Dim Wbk As Workbook
   Dim Ws As Worksheet

   FilePath = "C:\Users\Nick.Clark\Desktop\Compare.xlsx"
   Set Ws = ActiveWorkbook.ActiveSheet
   Set Owbk = Workbooks.Open(FilePath)
   Ws.move After:=Wbk.Sheets(Wbk.Sheets.Count)
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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