TheRobRush
New Member
- Joined
- Nov 5, 2018
- Messages
- 39
In my code below I was expecting the data to be saved to the storage file only when a item in column b was changed a different value.
However, even when you change (for example) Tickets to Tickets it adds these changes to the log file.
What am I missing?
However, even when you change (for example) Tickets to Tickets it adds these changes to the log file.
What am I missing?
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
' so far takes updates and stores them on cell a1 of sheet2 ONLY if column 2 (location) is edited
' stores all data as a csv file format scheduled,name,location,time,date,NEXTPERSON ad infinitum
Application.ScreenUpdating = False
Application.EnableEvents = False
'==============================================================
Dim assname
Dim asscombo
asssch = "Tickets"
assr = Target.Row
assc = Target.Column
If Target.Column = 2 Then
' assloc gives you the position changed to
' assname gives you the name of ermployee edited
' *******************REQUIRES CHANGE IN EACH SHEET USED FOR SHEET NAME
' try and change to active sheet
assloc = Worksheets("Sheet1").Cells(assr, 2).Value
assname = Worksheets("Sheet1").Cells(assr, 1).Value
' checks if change was to previous value, if so skips
Dim a, b
a = originalvalue
b = Target.Value
If Target.Value <> originalvalue Then
'===============trying to save directly all changes
Dim xl0 As New Excel.Application
Dim xlw As New Excel.Workbook
Dim j, v
Set xlw = xl0.Workbooks.Open("C:\Users\604034107\Desktop\BOARD TEST\AIO BOARD\TESTASSIGNMENTSTORAGE.xlsm")
' xl0.Worksheets.Add
j = xl0.Range("A1048576").End(xlUp).Row
v = j + 1
xl0.ActiveSheet.Cells(v, 1) = "Tickets"
xl0.ActiveSheet.Cells(v, 2) = assname
xl0.ActiveSheet.Cells(v, 3) = assloc
xl0.ActiveSheet.Cells(v, 4) = Date
xl0.ActiveSheet.Cells(v, 5) = Time
xlw.Save
xlw.Close
Set xl0 = Nothing
Set xlw = Nothing
'=================end experiment
End If
'end if for first if statement checking columnn
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
'==================================================================
End Sub