Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Move a sheet

Hello NG,
I have this macro I run on the first of the year and it works OK except for
the
Sheets(CurrentYear).Move After:=Sheets(WS_Count)
It doesn't seem to see or recognize this line, no errors or anything, just
skips over it.
Any suggestion on how I can get the new sheet to move to the last position?

Thanks
James

Dim CurrentYear As String
Dim LastYear As String
Dim WS_Count As Integer
CurrentYear = Right(Date, 4) 'get just the year from the current date


WS_Count = Worksheets.Count

Sheets.Add
Sheets("Sheet1").Name = CurrentYear
Sheets(CurrentYear).Select
Sheets(CurrentYear).Move After:=Sheets(WS_Count)
Sheets(CurrentYear).Select


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Move a sheet

James,

I would do it in the Add method like so....

Sub AddYearSheetToEnd()
Dim ws As Worksheet
Dim CurrentYear As String

CurrentYear = Right(Date, 4)

Set ws = Worksheets.Add(After:=Sheets(Sheets.Count))
ws.Name = CurrentYear

End Sub



--
Charles
www.officezealot.com


"James Agostinho" wrote in message
k.net...
Hello NG,
I have this macro I run on the first of the year and it works OK except

for
the
Sheets(CurrentYear).Move After:=Sheets(WS_Count)
It doesn't seem to see or recognize this line, no errors or anything, just
skips over it.
Any suggestion on how I can get the new sheet to move to the last

position?

Thanks
James

Dim CurrentYear As String
Dim LastYear As String
Dim WS_Count As Integer
CurrentYear = Right(Date, 4) 'get just the year from the current

date


WS_Count = Worksheets.Count

Sheets.Add
Sheets("Sheet1").Name = CurrentYear
Sheets(CurrentYear).Select
Sheets(CurrentYear).Move After:=Sheets(WS_Count)
Sheets(CurrentYear).Select




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Move a sheet

James,

A couple of things:

I'm not sure you can assume the new sheet will be named Sheet1, anyways you
don't need to assume so.
It might be simplet to do without the WS_count variable if you only use it
once.
You don't need to select the new sheet - it becomes the active sheet after
it's created.
I'd refer only to either sheets or worksheets (sheets includes chart sheets
if there are some).

This is how I'd write it:

Sub test()

Dim CurrentYear As String
Dim LastYear As String

CurrentYear = Right(Date, 4) 'get just the year from the current date

Sheets.Add
With ActiveSheet
.Name = CurrentYear
.Move After:=Sheets(Sheets.Count)
End With

End Sub

hth,

Doug

"James Agostinho" wrote in message
k.net...
Hello NG,
I have this macro I run on the first of the year and it works OK except

for
the
Sheets(CurrentYear).Move After:=Sheets(WS_Count)
It doesn't seem to see or recognize this line, no errors or anything, just
skips over it.
Any suggestion on how I can get the new sheet to move to the last

position?

Thanks
James

Dim CurrentYear As String
Dim LastYear As String
Dim WS_Count As Integer
CurrentYear = Right(Date, 4) 'get just the year from the current

date


WS_Count = Worksheets.Count

Sheets.Add
Sheets("Sheet1").Name = CurrentYear
Sheets(CurrentYear).Select
Sheets(CurrentYear).Move After:=Sheets(WS_Count)
Sheets(CurrentYear).Select




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to move rows from one sheet to another sheet (macro) Stacey Excel Discussion (Misc queries) 1 December 30th 09 02:52 PM
Creating form on sheet 1 and having info move to sheet 2 SHARON Excel Discussion (Misc queries) 4 June 1st 09 05:01 PM
How do I move daily data from one sheet to a 'yearly sheet' ClintH2007 Excel Worksheet Functions 3 September 10th 07 07:02 AM
Move data to new sheet - rename sheet based on criteria ? [email protected] Excel Discussion (Misc queries) 7 May 16th 07 10:22 PM
move rows of data seperated in a sheet to a sheet with no separat Lynn Excel Worksheet Functions 5 December 22nd 06 03:18 AM


All times are GMT +1. The time now is 12:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"