Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Code for Inserting Sheet in Excel 2000 not working in 2003

I'm tasked with running an employee contest using Excel. I wrote code at
home using Excel 2000 and it works fine. At work, using 2003, I run into
problems. In the spreadsheet there are 3 sheets that must not be changed (a
scoring summary, a master, and a dummy entry form that is copied as an
entrant's specific sheet). There are 4 forms. Form1 gives instructions,
Form2 creates the contestants sheet and adds their name and statistics to the
summary sheet, Form3 provides additional instructions and populates Form4,
From4 gets input from the participant and adds the data to their personal
sheet. The code below works fine in 2000 (copying the "Entry 1" sheet,
adding it in the 4th tab slot, and changing the name of the sheet). In 2003,
it works fine the first time (for the 1st contestant). But after saving and
exiting the spreadsheet, the next contestant to open the spreadsheet will
encounter problems as the code copies and adds one of the first 2 sheets
(scoring summary or master) instead of Entry1 sheet. Any thoughts.... I'm
new to VB code

Private Sub CommandButton1_Click()
UserForm2.Hide 'Hides form2 after disclaimer
Dim Entrant As String
Entrant = InputBox("Please Enter Your Name" & Chr(13) & "First Name and
Last Initial" & Chr(13) & "(For Example; John P)", "Enter New Contestant")
Sheets("Entry1").Select 'Base sheet to be copied and renamed to
entrant name
Sheets("Entry1").Copy After:=Sheets(3) 'Place new sheet in 4th tab slot
Sheets("Entry1 (2)").Select 'Select the new sheet
Sheets("Entry1 (2)").Name = Entrant 'Rename sheet
Range("G2:J2").Select 'Select rage for name to be inserted into the form
ActiveCell.FormulaR1C1 = Entrant 'Place entrant name in cells
Sheets("Scoring Summary").Select
Rows("6:6").Select
Selection.Insert Shift:=xlDown 'insert row to add entrant summary data
Range("C5:P5").Select
Selection.Copy
Range("C6").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Replace What:="Entry1", Replacement:="'" & Entrant & "'",
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False
Sheets(Entrant).Select
UserForm3.Show
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Code for Inserting Sheet in Excel 2000 not working in 2003

I could not determine exactly why you are getting the problem. However, when
you copy a worksheet, the new worksheet becomes the ActiveSheet so there is
no need to select it by it's new name; just use ActiveSheet. Try the
following and see if it is any better:-

UserForm2.Hide 'Hides form2 after disclaimer
Dim Entrant As String
Entrant = InputBox("Please Enter Your Name" & Chr(13) & _
"First Name and Last Initial" & Chr(13) & _
"(For Example; John P)", "Enter New Contestant")
Sheets("Entry1").Copy After:=Sheets(3) 'Place new sheet in 4th tab slot

ActiveSheet.Name = Entrant 'Rename sheet

Range("G2:J2").Select 'Select rage for name to be inserted into the form
ActiveCell.FormulaR1C1 = Entrant 'Place entrant name in cells
Sheets("Scoring Summary").Select
Rows("6:6").Select
Selection.Insert Shift:=xlDown 'insert row to add entrant summary data
Range("C5:P5").Select
Selection.Copy
Range("C6").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Replace What:="Entry1", Replacement:="'" & Entrant & "'",
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False
Sheets(Entrant).Select
UserForm3.Show

--
Regards,

OssieMac


"Enginerd88" wrote:

I'm tasked with running an employee contest using Excel. I wrote code at
home using Excel 2000 and it works fine. At work, using 2003, I run into
problems. In the spreadsheet there are 3 sheets that must not be changed (a
scoring summary, a master, and a dummy entry form that is copied as an
entrant's specific sheet). There are 4 forms. Form1 gives instructions,
Form2 creates the contestants sheet and adds their name and statistics to the
summary sheet, Form3 provides additional instructions and populates Form4,
From4 gets input from the participant and adds the data to their personal
sheet. The code below works fine in 2000 (copying the "Entry 1" sheet,
adding it in the 4th tab slot, and changing the name of the sheet). In 2003,
it works fine the first time (for the 1st contestant). But after saving and
exiting the spreadsheet, the next contestant to open the spreadsheet will
encounter problems as the code copies and adds one of the first 2 sheets
(scoring summary or master) instead of Entry1 sheet. Any thoughts.... I'm
new to VB code

Private Sub CommandButton1_Click()
UserForm2.Hide 'Hides form2 after disclaimer
Dim Entrant As String
Entrant = InputBox("Please Enter Your Name" & Chr(13) & "First Name and
Last Initial" & Chr(13) & "(For Example; John P)", "Enter New Contestant")
Sheets("Entry1").Select 'Base sheet to be copied and renamed to
entrant name
Sheets("Entry1").Copy After:=Sheets(3) 'Place new sheet in 4th tab slot
Sheets("Entry1 (2)").Select 'Select the new sheet
Sheets("Entry1 (2)").Name = Entrant 'Rename sheet
Range("G2:J2").Select 'Select rage for name to be inserted into the form
ActiveCell.FormulaR1C1 = Entrant 'Place entrant name in cells
Sheets("Scoring Summary").Select
Rows("6:6").Select
Selection.Insert Shift:=xlDown 'insert row to add entrant summary data
Range("C5:P5").Select
Selection.Copy
Range("C6").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Replace What:="Entry1", Replacement:="'" & Entrant & "'",
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False
Sheets(Entrant).Select
UserForm3.Show
End Sub

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
Simple VBA Code written in Excel 2003 not working in Excel 2000 Rich B. Excel Programming 4 August 3rd 07 04:36 PM
2nd try --Macro to transfer data in an Excel sheet (2000) in Access 2000 ( code to replace what wizard do) André Lavoie Excel Programming 0 September 27th 05 01:50 PM
Excel VB 2000 not working in 2003 A Lost Soul New Users to Excel 2 March 22nd 05 01:21 PM
Macro working in Excel 2003; not working in Excel 2000 Leslie Barberie Excel Programming 5 May 20th 04 07:51 PM
Excel 2000 code not working in XP Shane J Excel Programming 2 January 31st 04 03:40 AM


All times are GMT +1. The time now is 05:40 AM.

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"