Private Sub Worksheet_Activate()
Application.Calculation = xlManual
'Application.EnableEvents = False
'Application.CalculateFullRebuild
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim wss As Worksheet
'On Click goes to sheet name in column D
If Target.Column = [4] Then
Set wss = ThisWorkbook.Sheets(Target.Value) 'Set To the sheet named in the clicked cell
'Sheets(Target.Value).Activate
wss.Activate
'If the active sheet is named “ADH”
If wss.Name = "ADH" Then
'Find the next available row in Column B of the new sheet
Dim nextRow As Long
nextRow = wss.Cells(Rows.Count, "B").End(xlUp).Row + 1
'Copy the value from Column B of Sheet Providers
wss.Range("B" & nextRow).Value = Worksheets("Providers").Range("B" & Target.Row).Value
'Copy the value of Column C of Sheet Providers to Column A on the same row of Column B
wss.Range("A" & nextRow).Value = Worksheets("Providers").Range("C" & Target.Row).Value
End If

Dim sheetName As String
Dim rowValues As String
Dim FilePath As String
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Integer

'check if selection is in column A
If Target.Column <> 1 Or IsEmpty(Me.Range("D" & Target.Row)) Then Exit Sub
'Application.EnableEvents = True
'get sheet name from selected cell in column D
sheetName = Me.Range("D" & Target.Row).Value




'check if sheet name exists
'On Error Resume Next
'Set ws = ThisWorkbook.Sheets(sheetName)
'If ws Is Nothing Then
'MsgBox sheetName & " sheet does not exist.", vbExclamation
'Exit Sub
'End If
'On Error GoTo 0




'get last non-blank row in column J of the sheet
Set ws = ThisWorkbook.Sheets(sheetName)
lastRow = ws.Cells(Rows.Count, "J").End(xlUp).Row

'get values from the last row
For i = 1 To 10 'A-J
rowValues = rowValues & ws.Cells(lastRow, i).Value & ","
Next i
rowValues = Left(rowValues, Len(rowValues) - 1) 'remove last comma

'create text file with row values
FilePath = "G:\Shared drives\Swan School Site Premises\PREMISES MANAGEMENT\SERVICE PROVIDERS\LastJob.txt" 'replace with your desired file path
'Open FilePath For Output As #1
'Print #1, rowValues
'Close #1

Open FilePath For Output As #1
For i = 1 To 10 'A-J
Print #1, ws.Cells(lastRow, i).Value
Next i
Close #1

'open text file
Shell "notepad.exe " & FilePath, vbNormalFocus 'replace notepad.exe with your preferred text editor
End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$I$2" Then
' Exit the rest of the sub if the target is I2
Application.EnableEvents = True
Application.CalculateFullRebuild
'MsgBox ("Close Prompt, Press Keyboard F9 or Scroll Up Down to show Results")
Exit Sub
End If

' Prompt for confirmation before undoing changes
Dim confirmation As VbMsgBoxResult
confirmation = MsgBox("Do you want to save this change?", vbYesNo)
If confirmation = vbNo Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
Exit Sub
End If

End Sub

'Private Sub Worksheet_Deactivate()
    'Application.EnablEvents = False
'End Sub


Part of this code opened a text document and appended to it the values of the last row of the sheet it refered to.
Now the code has stopped working.
Can you identify the error