Hi all. I have a code that is working as expected, but I need it on every new sheet that is added via VBA
The code I need added to every new sheet is:
The code I am using to add new pages is:
Thanks for any help - Jim A
The code I need added to every new sheet is:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If CheckBox1.Value = False Then Exit Sub
If (Target.Column <> 5) Then Exit Sub
If (Target = "") Then Exit Sub
Dim cRNG As Range
Set cRNG = Worksheets(4).Range("E:E")
With cRNG
Call Lookup(Target)
End With
End Sub
Sub Lookup(Target As Range)
Application.ScreenUpdating = False
Dim pFind As Range
On Error GoTo ErrorSpot
Set pFind = Sheets(1).Range("A:Z").find(What:=Target.Value, LookIn:=xlValues, LookAt:=xlPart).Offset(, -4).Resize(1, 11)
Target.Offset(, -4).Resize(1, 11).Value = pFind.Value
ErrorSpot:
MsgBox "CDCR# not found on SOMs Sheet."
Range("A3").Activate
Application.ScreenUpdating = True
End Sub
The code I am using to add new pages is:
Code:
Dim K
Dim wb As Workbook
Dim ws, wsNEW As Worksheet
Dim sNm As String
'checking if sheet already exists in workbook
Set wb = ActiveWorkbook
sNm = Cells(3, 1) 'Text in cell A3 will be tested or become new sheet
For Each ws In wb.Worksheets
If ws.Name = sNm Then
MsgBox ("Sheet " & sNm & " already exists")
Exit Sub
End If
Next
'MsgBox ("Working so far!")
'new sheet required
Set wsNEW = Sheets.Add
wsNEW.Move After:=Worksheets(Worksheets.Count) 'move to end
wsNEW.Name = sNm
Thanks for any help - Jim A