ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Moving worksheet (https://www.excelbanter.com/excel-programming/349866-moving-worksheet.html)

AK

Moving worksheet
 
Please help:-

There are 2 workbooks and I want to move all the sheets(except the sheet
with name ="Sheet1", "Sheet2"...) in "Workbook A" to "Workbook B", how can I
write in VB?

Martin Fishlock[_3_]

Moving worksheet
 
Dear AK,

Here is one way to do it:

Sub movesheets()
Dim ws As Worksheet
Dim wbs As Workbook
Dim wbd As Workbook

Set wbs = Workbooks("Workbook A.xls")
Set wbd = Workbooks("Workbook B.xls")

For Each ws In wbs.Worksheets
If Not (ws.Name = "Sheet1" Or ws.Name = "Sheet2") Then
ws.Move after:=wbd.Worksheets(wbd.Worksheets.Count)
End If
Next ws
Set ws = Nothing
Set wbs = Nothing
Set wbd = Nothing
End Sub

--
HTHs Martin


"ak" wrote:

Please help:-

There are 2 workbooks and I want to move all the sheets(except the sheet
with name ="Sheet1", "Sheet2"...) in "Workbook A" to "Workbook B", how can I
write in VB?



All times are GMT +1. The time now is 09:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com