S
Susan Hayes
Hi again
Im trying to check an area of the worksheet (ie e4:n13) whether the
number entered by the user already exists in that area. Currently my
program uses activecell but, after the user has entered the value for
example, in e5, pressed enter, the activecell becomes e6 and the
program doesnt work. How can you obtain what the user has just
entered in e5. I could move the cell up but the user may tab instead!
Thank you
John
Private Sub Worksheet_Change(ByVal Target As Range)
'Application.EnableEvents = False
'On Error GoTo ws_exit
If Not Intersect(Target, Range("e4:n13")) Is Nothing Then
With Target
''''''''''''''''''''''''''''''''''''''''
Dim myarray(20, 10)
Dim currentlane
Dim checkvalue
' ******* shows me the cell after pressing enter********
Dim rng As Range
Set rng = ActiveCell
Dim generalrng As Range
Cells(35, "d") = rng.Address(0, 0)
' ******************************************************
currentlane = .Value
checkvalue = IsNumeric(currentlane)
'reads the existing area
For i = 1 To 10
For j = 1 To 10
Set generalrng = Cells(i + 3, Chr(68 + j))
If Not rng = generalrng Then
myarray(i, j) = Cells(i + 3, Chr(68 + j))
End If
Next
Next
'performs check using activecell
If checkvalue = True Then 'And currentlane < MAXLANEVALUE Then
For i = 1 To 10
For j = 1 To 10
'Set generalrng = ActiveCell
If Not rng = generalrng Then
If .Value = myarray(i, j) Then
Cells(1, "K") = "duplicate"
Exit Sub
End If
End If
Next
Next
End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End With
End If
'ws_exit:
' Application.EnableEvents = True
End Sub
Im trying to check an area of the worksheet (ie e4:n13) whether the
number entered by the user already exists in that area. Currently my
program uses activecell but, after the user has entered the value for
example, in e5, pressed enter, the activecell becomes e6 and the
program doesnt work. How can you obtain what the user has just
entered in e5. I could move the cell up but the user may tab instead!
Thank you
John
Private Sub Worksheet_Change(ByVal Target As Range)
'Application.EnableEvents = False
'On Error GoTo ws_exit
If Not Intersect(Target, Range("e4:n13")) Is Nothing Then
With Target
''''''''''''''''''''''''''''''''''''''''
Dim myarray(20, 10)
Dim currentlane
Dim checkvalue
' ******* shows me the cell after pressing enter********
Dim rng As Range
Set rng = ActiveCell
Dim generalrng As Range
Cells(35, "d") = rng.Address(0, 0)
' ******************************************************
currentlane = .Value
checkvalue = IsNumeric(currentlane)
'reads the existing area
For i = 1 To 10
For j = 1 To 10
Set generalrng = Cells(i + 3, Chr(68 + j))
If Not rng = generalrng Then
myarray(i, j) = Cells(i + 3, Chr(68 + j))
End If
Next
Next
'performs check using activecell
If checkvalue = True Then 'And currentlane < MAXLANEVALUE Then
For i = 1 To 10
For j = 1 To 10
'Set generalrng = ActiveCell
If Not rng = generalrng Then
If .Value = myarray(i, j) Then
Cells(1, "K") = "duplicate"
Exit Sub
End If
End If
Next
Next
End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End With
End If
'ws_exit:
' Application.EnableEvents = True
End Sub