Patriot2879
Well-known Member
- Joined
- Feb 1, 2018
- Messages
- 1,259
- Office Version
- 2010
- Platform
- Windows
Hi I have the code below but I get an ambiguous name error come up please can you help.
the error comes on the line below
the error comes on the line below
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'This code goes in Book13, amend for book 14
'this sub requires both workbooks to be open
Dim wb As Workbook
Dim spath As String, sFileName As String
Dim bOpen As Boolean 'remember if workbook was open or not
spath = "C:\Users\s21375\Desktop\"
' *** This line needs changing for Book 14
sFileName = "Test1.xlsm"
On Error Resume Next
Set wb = Workbooks(sFileName)
If wb Is Nothing Then
Set wb = Workbooks.Open(spath & sFileName)
If wb Is Nothing Then
MsgBox "File can not be opened", vbCritical
Exit Sub
End If
Else
bOpen = True
End If
On Error GoTo 0
Application.EnableEvents = False
Application.ScreenUpdating = False
wb.Sheets(Me.Name).Range(Target.Address) = Target
If bOpen = False Then
wb.Save
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
If Not Intersect(Target, Me.Range("A2:R18")) Is Nothing Then
ThisWorkbook.Save
End If
End Sub