Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
DNA
 
Posts: n/a
Default Need Help With A Macro

I'm thinking this is a Macro...

I have a workbook with Sheets named 06-08-05, 06-09-05, etc. Everyday
when I open the workbook, I'd like to have a new sheet that automatically
gets created, is named with the next "date" (i.e., 06-10-05 in this
example) and copies all data from the previous days Sheet to this new one.
How?

Thanks so much for your help!!

David

  #2   Report Post  
Jason Morin
 
Posts: n/a
Default

Press ALT+F11, click on the "ThisWorkbook" module to the left, and paste the
code below in the window to the right:

Sub Workbook_Open()

Dim iTotalSheets As Long
Dim strLastSheet As String

iTotalSheets = ActiveWorkbook.Worksheets.Count
strLastSheet = Sheets(iTotalSheets).Name

Sheets(iTotalSheets).Copy After:=Sheets(iTotalSheets)
Sheets(iTotalSheets + 1).Name = Format(CDate(strLastSheet) + 1,
"mm-dd-yy")

End Sub

---

Press ALT+Q and save.

HTH
Jason
Atlanta, GA


"DNA" wrote:

I'm thinking this is a Macro...

I have a workbook with Sheets named 06-08-05, 06-09-05, etc. Everyday
when I open the workbook, I'd like to have a new sheet that automatically
gets created, is named with the next "date" (i.e., 06-10-05 in this
example) and copies all data from the previous days Sheet to this new one.
How?

Thanks so much for your help!!

David


  #3   Report Post  
DNA
 
Posts: n/a
Default

Thanks a bunch. I am though, getting a syntax error with this line:

Sheets(iTotalSheets + 1).Name = Format(CDate(strLastSheet) + 1,
"mm-dd-yy")

  #4   Report Post  
DNA
 
Posts: n/a
Default

MY BAD ... it was me, thanks SO MUCH!!!

  #5   Report Post  
DNA
 
Posts: n/a
Default

One more thing. Each sheet has a date in B2, can I get that to change to
the next date as well?



  #6   Report Post  
Jason Morin
 
Posts: n/a
Default

I changed the code a little and added your request to the end:

Sub Workbook_Open()

Dim iTotalSheets As Long
Dim strLastSheet As String
Dim wsNewLastSheet As Worksheet

iTotalSheets = ActiveWorkbook.Worksheets.Count
strLastSheet = Sheets(iTotalSheets).Name

Sheets(iTotalSheets).Copy After:=Sheets(iTotalSheets)
Set wsNewLastSheet = Sheets(iTotalSheets + 1)
wsNewLastSheet.Name = Format(CDate(strLastSheet) + 1, "mm-dd-yy")

With wsNewLastSheet.[B2]
.Value = .Value + 1
End With

End Sub


---
HTH
Jason
Atlanta, GA


"DNA" wrote:

One more thing. Each sheet has a date in B2, can I get that to change to
the next date as well?


  #7   Report Post  
DNA
 
Posts: n/a
Default

Where should the lines break correctly within the code? That's the problem
I'm having when pasting...

  #8   Report Post  
Jason Morin
 
Posts: n/a
Default

I messed up before, but the code should be pasted in as it looks now.

Jason

"DNA" wrote:

Where should the lines break correctly within the code? That's the problem
I'm having when pasting...


  #9   Report Post  
DNA
 
Posts: n/a
Default

Got it, thanks again Jason!!

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
Help with macro looping and color query function kevinm Excel Discussion (Misc queries) 10 May 26th 05 01:25 AM
Issuing macro in workbook from separate workbook Nigel Excel Discussion (Misc queries) 1 May 16th 05 05:46 PM
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM
Macro and If Statement SATB Excel Discussion (Misc queries) 2 December 3rd 04 04:46 PM


All times are GMT +1. The time now is 11:57 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"