If i enter an Invoice number..etc on my Data Input Sheet it then sends the data to the Data Sheet Via Macro. Is there a Formula i can put into the (Invoice #)Cell ,that when i type in an Invoice it would Alert me that its already used?
If i enter an Invoice number..etc on my Data Input Sheet it then sends the data to the Data Sheet Via Macro. Is there a Formula i can put into the (Invoice #)Cell ,that when i type in an Invoice it would Alert me that its already used?
Here is a macro that you can use:
Sub find_value(Target)
Dim SHT As Worksheet
Dim rFND As Range
strSearch = Target.Value
If strSearch <> "" Then
Set rFND = Nothing
' Sheet2 is the name of the sheet where the value might already be contained.
Set rFND = Sheets("Sheet2").Cells.Find(What:=strSearch, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlRows, SearchDirection:=xlNext, MatchCase:=False)
If Not rFND Is Nothing Then
msg_response = MsgBox("Value already exists.", vbOK)
Target.Clear
GoTo OutsideLoop
End If
End If
OutsideLoop:
End Sub
It is modified from the code here: Macro to Find All text or values in the workbook
Then, in the worksheet where you want the macro to run, input this macro code:
Private Sub Worksheet_Change(ByVal Target As Range)
' You can also use Target.Column = 1 or 2 or 3 etc.
' 1 = column A, 2 = Column B, etc.
If Target.Address = "$A$1" Then
Call find_value(Target)
End If
End Sub
This is what will run each time the user changes a cell value in the worksheet; it will only run in the workshet that you put it into.
To get to the code window for a worksheet, right-click its tab and click View Code.
You can learn more about the second macro here: Run a Macro When a Specific Cell Changes in Excel