Move one worksheet within workbook for multiple workbooks

Hawks85

New Member
Joined
Sep 20, 2017
Messages
3
Hi,

I have a set of workbooks which all contain a worksheet called "Data". I need to move this worksheet to the beginning of each workbook. I'd like to set up a macro to do this for all workbooks simultaneously.

I have the following code, but it only seems to move the worksheet in the currently active workbook, and doesn't move on to the next workbook.

Code:
Sub MoveData()

Dim wb As Workbook

For Each wb In Workbooks

Worksheets("Data").Move Before:=Worksheets(1)

Next wb

End Sub

What am I missing?
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Never mind, I solved the problem :)

Code:
Sub MoveData()

Dim wb As Workbook

For Each wb In Workbooks

[COLOR=#FF0000]If wb.Name <> "PERSONAL.XLSB" Then[/COLOR]
[COLOR=#ff0000]wb.[/COLOR]Worksheets("Data").Move Before:=[COLOR=#FF0000]wb.[/COLOR]Wor[COLOR=#FF0000][/COLOR]ksheets(1)
[COLOR=#FF0000]End If[/COLOR]

Next wb

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

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