LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default auto insert copy of worksheet

I want to create a workbook to track test anomalies. The first worksheet is a log sheet and then each subsequent worksheet is the detailed information about that anomaly. (i.e., the 2nd worksheet would be named TA001, the 3rd worksheet would be named TA003, etc.) I found the following macro that auto inserts worksheets named whatever you enter on the first worksheet (in this case the log). So, as new test anomalies are entered on the log sheet, a new worksheet for that test anomaly is inserted. However, I want the worksheet that are inserted to all be the same (cell A1 says "Date", cell A2 says "Title", etc) Is there any way that it can automatically insert a copy of the 2nd worksheet? Any help will be greatly appreciated. Thanks in advance.

Private Sub Worksheet_Change(ByVal Target As Range)

Application.ScreenUpdating = False

Dim wks As Worksheet
Dim myVal As String
Dim resp As Long

'too many cells at once!
If Target.Cells.Count 1 Then Exit Sub

'Must be in column A (=1)
If Target.Column < 1 Then Exit Sub

'must be after row 1
If Target.Row < 2 Then Exit Sub

myVal = CStr(Target.Value)

Set wks = Nothing
On Error Resume Next
Set wks = Worksheets(myVal)
On Error GoTo 0

If wks Is Nothing Then
'worksheet doesn't already exist
Set wks = Worksheets.Add(after:=Target.Parent)
Me.Activate
On Error Resume Next
wks.Name = myVal
If Err.Number 0 Then
Application.ScreenUpdating = True
If MsgBox(prompt:="Can't add this sheet." & vbLf & _
"Should I delete the new one?", _
Buttons:=vbYesNo + vbCritical, _
Title:="Warning") = vbYes Then
Application.DisplayAlerts = False
wks.Delete
Application.DisplayAlerts = True
Else
MsgBox "Please Rename " & wks.Name & " manually"
End If
Application.ScreenUpdating = False
End If
On Error GoTo 0
Else
MsgBox "A worksheet named " & wks.Name & " already exists" & _
vbLf & "Not added!", Buttons:=vbCritical
End If

End Sub

 
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
Auto-insert same value each Monday in cashflow worksheet? Scribble Excel Worksheet Functions 0 April 13th 10 02:41 PM
Insert row in Master worksheet that auto inserts in other workshee mary p Excel Discussion (Misc queries) 3 February 16th 09 08:21 PM
Move/Copy or Copy/Insert worksheet? kjk Excel Discussion (Misc queries) 0 December 15th 06 02:40 PM
Unable to Insert Worksheet/Move and copy worksheet Excel 2003 lukerush Excel Worksheet Functions 2 September 7th 06 05:05 PM
Can I auto insert a worksheet when I insert a value in a cell. iainc Excel Worksheet Functions 0 April 27th 06 08:37 AM


All times are GMT +1. The time now is 03:00 AM.

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

About Us

"It's about Microsoft Excel"