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: 13
Default Worksheet change when creating new sheet

I using the macro below to create worksheet from a list of names.


Private Function SheetExists(SHName As String, WB As Workbook) As
Boolean
On Error Resume Next
SheetExists = CBool(Len(WB.Worksheets(SHName).Name))
End Function


Sub CreateSheetsFromList()
Dim R As Range
For Each R In Selection.Cells
If R.Text < vbNullString Then
If SheetExists(R.Text, ThisWorkbook) = False Then
With ThisWorkbook.Worksheets
.Add(after:=.Item(.Count)).Name = R.Text
End With
End If
End If


Next R
End Sub


I would like to have the same Workshet Change event for each sheet
created:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyRow As Long
If Target.Column < 2 Then Exit Sub
If WorksheetFunction.CountIf(Range("B:B"), Target.Value) 1 Then
MyRow = WorksheetFunction.Match(Target.Value, Range("B:B"), 0)
response = MsgBox("That number has been used on row " _
& MyRow & " Yes to continue NO to cancel", vbYesNo, "Warning")
If response = vbYes Then
Exit Sub
Else
Target.ClearContents
End If
End If
End Sub



How can I have the code add the change event when it creates a new
worksheet?


Thanks
 
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
Worksheet Change Event - copy cell to another sheet dhstein Excel Discussion (Misc queries) 2 October 12th 09 06:35 PM
automatically change the worksheet reference when new sheet added Joel Excel Worksheet Functions 8 November 29th 08 01:01 AM
Q: Creating a macro to sort and group columns in a sheet according to another sheet [email protected] Excel Programming 0 January 8th 07 09:06 PM
using 2 Worksheet Change Event in a sheet, is it possible? Rajat Excel Programming 3 November 25th 06 08:09 AM
Change worksheet formulas from button on chart sheet David Excel Programming 1 November 15th 05 03:17 PM


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