Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / January 2008

Tip: Looking for answers? Try searching our database.

simple macro to copy a sheet, object undefined error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Excel-General - 18 Jan 2008 21:05 GMT
I'm still having trouble with objects, but i can't figure out which
one.

Sub CopySheet()
Dim wb As Workbook
Set wb = ThisWorkbook

wb.Sheets(2).Copy Type:=xlWorksheet, after:=Sheets(2)

End Sub

tnx,
Dave Peterson - 18 Jan 2008 21:26 GMT
How about:

Option Explicit
Sub CopySheet()
 Dim wb As Workbook
 Set wb = ThisWorkbook
 wb.Sheets(2).Copy after:=wb.Sheets(2)
End Sub

> I'm still having trouble with objects, but i can't figure out which
> one.
[quoted text clipped - 8 lines]
>
> tnx,

Signature

Dave Peterson

Excel-General - 18 Jan 2008 22:01 GMT
> How about:
>
[quoted text clipped - 21 lines]
>
> Dave Peterson

thanks,
Excel-General - 18 Jan 2008 22:47 GMT
> How about:
>
[quoted text clipped - 7 lines]
> > I'm still having trouble with objects, but i can't figure out which
> > one.
I revised it slightly to rename the copied sheet.  It works but it
doens't rename the sheet.  How can I fix it so it names my new sheet
with a global variable name.  Thanks
> > Sub CopySheet()
> > Dim wb As Workbook
[quoted text clipped - 9 lines]
>
> Dave Peterson

Hi, I revised it slightly to rename the new sheet however it doesn't
rename the sheet.  g_Fname is a global variable.
I would like it to name the new sheet moved to index 2 with the global
first name.  Thanks.

Sub CopySheet()
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ThisWorkbook

wb.Sheets(2).Copy after:=Sheets(2)
Set ws = wb.Sheets(3)
ws.Name = "m_Fname"
End Sub
Dave Peterson - 19 Jan 2008 00:57 GMT
You didn't qualify the "after:=" sheets.  You didn't use g_Fname anywhere in
your code.  And if you use "before:=" instead of "after:=", then the sheet will
be in the correct location.  (Or use after:=wb.sheets(1))

Sub CopySheet()
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ThisWorkbook

wb.Sheets(2).Copy before:=wb.Sheets(2)
Set ws = wb.Sheets(2)
ws.Name = g_Fname
End Sub

<<snipped>>

> Hi, I revised it slightly to rename the new sheet however it doesn't
> rename the sheet.  g_Fname is a global variable.
[quoted text clipped - 10 lines]
> ws.Name = "m_Fname"
> End Sub

Signature

Dave Peterson

Excel-General - 19 Jan 2008 01:24 GMT
> You didn't qualify the "after:=" sheets.  You didn't use g_Fname anywhere in
> your code.  And if you use "before:=" instead of "after:=", then the sheet will
[quoted text clipped - 16 lines]
> > I would like it to name the new sheet moved to index 2 with the global
> > first name.  Thanks.
thanks,

> > Sub CopySheet()
> > Dim wb As Workbook
[quoted text clipped - 9 lines]
>
> Dave Peterson
Excel-General - 19 Jan 2008 01:25 GMT
> You didn't qualify the "after:=" sheets.  You didn't use g_Fname anywhere in
> your code.  And if you use "before:=" instead of "after:=", then the sheet will
[quoted text clipped - 30 lines]
>
> Dave Peterson

That was really smart by the way to do it before and put it in front
of itself.
Dave Peterson - 19 Jan 2008 01:39 GMT
Sometimes, it's an extra pair of eyes helping to get what you need.

<<snipped>>

> That was really smart by the way to do it before and put it in front
> of itself.

Signature

Dave Peterson

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.