The Target is the cell that is being changed by the user (which is the event that triggers this code to execute).
If you want to check the value of the datum being entered by the user against your specs, then you would get the value of the Target cell and then use it to compare.
Here's some pseudo-code to give you the idea. If you post your current code then we can tweak it.
VB Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim dInputValue As Double
'First we check if the value entered is numeric
If IsNumeric(Target.Value) Then
'Then we pass it to a variable
dInputValue = Target.Value
'now test the dInputValue variable against your specs
End If
End Sub
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful
'This loops the macro for each row of measured features of the report until a blank row is found.
Do While Cells(x, 7).Value <> ""
'This makes sure the "Status" field begins with a blue "ok" statement.
Cells(x, 14).Value = "ok"
Cells(x, 14).Font.ColorIndex = 5
Cells(x, 14).Font.FontStyle = "Normal"
'This loops the macro to checks each sample within the report until a blank column is found.
Do While Cells(x, y).Value <> ""
'This checks to see what type of tolerance there is: Bi-Lateral, Minus,or plus.
'Bi-Lateral Formulas
If Cells(x, 4) = "Bi-Lateral" Then
'Then it checks if the measured value is in/out based on a bi-lateral tolerance.
If Cells(x, y).Value < Cells(x, 5).Value - Cells(x, 6).Value / 2 Or Cells(x, y).Value > Cells(x, 5).Value + Cells(x, 6).Value / 2 Then
'If found "OOT"; sets the text of the measured value to red and sets the background to grey.
Cells(x, y).Interior.ColorIndex = 6
Cells(x, y).Font.ColorIndex = 3
Cells(x, y).Font.FontStyle = "Bold"
'In the event corrections are made; resets the font and background back to normal if now in tolerance.
ElseIf Cells(x, y).Value >= Cells(x, 5).Value - Cells(x, 6).Value / 2 Or Cells(x, y).Value <= Cells(x, 5).Value + Cells(x, 6).Value / 2 Then
'This will place a red "OOT" in the "Status" when there is an OOT condition found for that feature.
If Cells(x, y).Value < Cells(x, 5).Value - Cells(x, 6).Value / 2 Or Cells(x, y).Value > Cells(x, 5).Value + Cells(x, 6).Value / 2 Then
'Then it checks if the measured value is in/out based on a minus tolerance.
If Cells(x, y).Value < Cells(x, 5).Value - Cells(x, 6).Value Or Cells(x, y).Value > Cells(x, 5).Value Then
'If found "OOT"; sets the text of the measured value to red and sets the background to grey.
Cells(x, y).Interior.ColorIndex = 6
Cells(x, y).Font.ColorIndex = 3
Cells(x, y).Font.FontStyle = "Bold"
'In the event corrections are made; resets the font and background back to normal if now in tolerance.
ElseIf Cells(x, y).Value >= Cells(9, 5).Value - Cells(9, 6).Value Or Cells(9, y).Value <= Cells(9, 5).Value Then
'This will place a red "OOT" in the "Status" when there is an OOT condition found for that feature.
If Cells(x, y).Value < Cells(x, 5).Value - Cells(x, 6).Value Or Cells(x, y).Value > Cells(x, 5).Value Then
'Then it checks if the measured value is in/out based on a plus tolerance.
If Cells(x, y).Value < Cells(x, 5).Value Or Cells(x, y).Value > Cells(x, 5).Value + Cells(x, 6).Value Then
'If found "OOT"; sets the text of the measured value to red and sets the background to grey.
Cells(x, y).Interior.ColorIndex = 6
Cells(x, y).Font.ColorIndex = 3
Cells(x, y).Font.FontStyle = "Bold"
'In the event corrections are made; resets the font and background back to normal if now in tolerance.
ElseIf Cells(x, y).Value >= Cells(x, 5).Value Or Cells(x, y).Value <= Cells(x, 5).Value + Cells(x, 6).Value Then
'This will place a red "OOT" when there is an OOT condition found for that feature.
If Cells(x, y).Value < Cells(x, 5).Value Or Cells(x, y).Value > Cells(x, 5).Value + Cells(x, 6).Value Then
This was written to compare 5 sample's measurement data against the drawing information (nominal value, type of tolerance, and tolerance range). If any one sample fails- turn the text bold and red and turn the background yellow. Also, at the end of the data stream, if it fails, put the letters "OOT" (Out of Tolerance) in the next column. Do this for as many rows of data available.
I may be way off here, but based on the info you have provided I came up with a demo that I think will give you what you need without any VBA code.
Have a look at the attached s/sheet and try some of you data in the box to see if the formulas and conditional formatting are working. I've tried to match to your columns as much as possible, without having seen your worksheet.
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful