Move sheet

User avatar
VegasNath
5StarLounger
Posts: 1185
Joined: 24 Jan 2010, 12:02
Location: Wales, UK.

Move sheet

Post by VegasNath »

I am using code like:

Code: Select all

wb1.Sheets(Format(strDateWork, "dd")).Copy Before:=wb2.Sheets("End")
This works fine if "End" is visible but not if it is hidden. Any idea how I can overcome this?
:wales: Nathan :uk:
There's no place like home.....

User avatar
HansV
Administrator
Posts: 78549
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Move sheet

Post by HansV »

If a sheet is hidden, it is not clear what "Before" would mean - "Before" refers to the visual order of the sheets.
So you'll have to specify a visible (non-hidden) sheet instead of End.
Or make End visible, move the other sheet, then hide End again.
Best wishes,
Hans

User avatar
VegasNath
5StarLounger
Posts: 1185
Joined: 24 Jan 2010, 12:02
Location: Wales, UK.

Re: Move sheet

Post by VegasNath »

HansV wrote:Or make End visible, move the other sheet, then hide End again.
Easy enough I guess, Thanks Hans. I would want to hide both end and the moved sheet, could that be done with a single statement, or separately?
:wales: Nathan :uk:
There's no place like home.....

User avatar
HansV
Administrator
Posts: 78549
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Move sheet

Post by HansV »

You can use

Worksheets(Array(strDateWork,"End")).Visible = xlSheetHidden

Note that the first array element doesn't have quotes around it, since it is the name of a variable.
Best wishes,
Hans

User avatar
VegasNath
5StarLounger
Posts: 1185
Joined: 24 Jan 2010, 12:02
Location: Wales, UK.

Re: Move sheet

Post by VegasNath »

:thankyou:
:wales: Nathan :uk:
There's no place like home.....