Adding this gave me an error.
Below is the code i currently have:
Option Explicit
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
On Error Resume Next
'Define your variables.
Dim ws As Worksheet, EvalRange As Range
'Set the range where you want to prevent duplicate entries.
Set EvalRange = Range("A1:A60")
'If the value entered already exists in the defined range on the current worksheet, throw an
'error message and undo the entry.
If WorksheetFunction.CountIf(EvalRange, Target.Value) > 1 Then
MsgBox Target.Value & " - the bilagsnr already exists on this sheet."
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
'Check the other worksheets in the workbook.
For Each ws In Worksheets
With ws
If .Name <> Target.Parent.Name Then
'If the value entered already exists in the defined range on the current worksheet, throw an
'error message and undo the entry.
If WorksheetFunction.CountIf(Sheets(.Name).Range("A1:A999"), Target.Value) > 0 Then
MsgBox Target.Value & " - bilagsnr already exists on the sheet named " & .Name & ".", _
16, "Duplicate found!"
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
Exit For
End If
End If
End With
Next ws
End Sub
Where should I add the new code?
Bookmarks