x needs to be a Variant rather than Long, then
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo dang
Build
Application.EnableEvents = False
If Target.Column = 3 And Target.Row = TestsTaken + 7 Then
item = Cells(Target.Row, 3)
x = Application.Match(item, PTests, 0)
If IsError(x) Then
MsgBox "Please Insert Valid PTest"
Cells(Target.Row, 3) = vbNullString
Else
Cells(Target.Row, 2) = Date + Time
Cells(Target.Row, 1) = Target.Row - 6
Cells(Target.Row, 3).Font.Color = 16711680
Cells(Target.Row, 1).Resize(1, 2).HorizontalAlignment = xlCenter
Cells(Target.Row, 6) = Application.Index(PTests, x, 0)
End If
End If
TestsTaken = Sheet3.Cells(Distance, 1).End(xlDown)
Build
dang:
Application.EnableEvents = True
End Sub
I can't begin to emphasize enough that you really oughta stop using so many public variables. For instance why is x public?
also in this code
With Sheets("Contents")
For i = 1 To Sheets.Count
Cells(i + 1, 2) = Sheets(i).Name
Cells(i + 1, 1) = i
Next i
End With
your with statement doesn't do anything. the code oughta be
With Sheets("Contents")
For i = 1 To Sheets.Count
.Cells(i + 1, 2) = Sheets(i).Name
.Cells(i + 1, 1) = i
Next i
End With
note the periods that qualify the Cells property calls
Bookmarks