Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linking New sheet to recorded information

Status
Not open for further replies.

sdfreed

Materials
Oct 26, 2003
6
I created a new worksheet with the current date in a macro. With the recorder I cut and pasted data into the new sheets. But the next day when the date changes, the macro doesn't work because it identifies with the worksheet name on the date recorded
The code for the date is:

Dim a As Worksheet
On Error Resume Next
Set a = Sheets([text(today(),"mm-dd-yyyy")])
If Err.Number = 0 Then Exit Sub
Application.ScreenUpdating = False
Set a = ActiveWorkbook.Worksheets.Add(after:=Sheets(Sheets.Count))
a.Name = [text(today(),"mm-dd-yyyy")] & " Quotes"
Application.ScreenUpdating = True
Set a = Nothing

And when it is running the macro is uses:

Range("A1:L11").Select
Selection.Copy
Sheets("10-29-2003 Quotes").Select
ActiveSheet.Paste

I tried changing: Sheets("10-29-2003 Quotes").Select
To: Sheets(a).Select But that did not want to take it.

Is this something right in front of me that I can't see???

Thanks in advance
 
Replies continue below

Recommended for you

The variable a does not represent a worksheet name, but is rather a full worksheet object.

The first thing I would try is the following:

Sheets(a.Name).Select
 
I tried that and it does not work. I think it has to do with the name being a variable? I just can't put my finger on it. Thanks for the reply, I really appreciate it.
 
A few thoughts:

Is your code in two different Subs? Excel will not know in the second Sub what a was earlier.
Next, you set a = nothing in the first part of code. This will release the object a, so you can no longer reference it.
3rd, if you properly have set a to a sheet (by Set a =ActiveWorkbook.Worksheets.Add, you can select the sheet simply by a.Select
So you can try setting a again to the proper sheet once that has been added if required:
Code:
   Set a = Sheets([text(today(),"mm-dd-yyyy")])
   ActiveSheet.Range("A1:L11").Copy
   a.Paste
I hope I understood you correctly...


Cheers,
Joerd

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
That did it. Thanks for helping out.

I just have one more question to post and I think I have this program completed! Everyone has been great on this site.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor