Hello,
Good day!
May I ask for your help? I'm having trouble in creating If statement with different criteria. The criteria are create, update and delete.
Created: Newly added data will be tagged as "Created + date it was created" on the "status" column
Updated: Existing data but you update something then it will be tagged as "Updated + date it was updated" on the "status" column
Deleted: If Column Test 4 was tagged as "No" then "status" column will be tagged as "Deleted + date it was deleted"
*Old - if no changes
The criteria will only be applied if changes made are not under the column with field name "Check".
Below is a sample scenario.
[TABLE="width: 492"]
<tbody>[TR]
[TD]Status
[/TD]
[TD]Test 1
[/TD]
[TD]Test 2
[/TD]
[TD]Test 3
[/TD]
[TD]Test 4
[/TD]
[TD]Check - XXXX
[/TD]
[/TR]
[TR]
[TD]Old
[/TD]
[TD]Data 1
[/TD]
[TD]Data 8
[/TD]
[TD]Data 15
[/TD]
[TD]Yes
[/TD]
[TD="align: right"]1
[/TD]
[/TR]
[TR]
[TD]Deleted
[/TD]
[TD]Data 2
[/TD]
[TD]Data 9
[/TD]
[TD]Data 16
[/TD]
[TD]No
[/TD]
[TD="align: right"]2
[/TD]
[/TR]
[TR]
[TD]Created
[/TD]
[TD]Data 3
[/TD]
[TD]Data 10
[/TD]
[TD]Data 17
[/TD]
[TD]Yes
[/TD]
[TD="align: right"]3
[/TD]
[/TR]
[TR]
[TD]Updated
[/TD]
[TD]Data 4
[/TD]
[TD]Data 11
[/TD]
[TD]Data 18
[/TD]
[TD]Yes
[/TD]
[TD="align: right"]4
[/TD]
[/TR]
[TR]
[TD]Old
[/TD]
[TD]Data 5
[/TD]
[TD]Data 12
[/TD]
[TD]Data 19
[/TD]
[TD]No
[/TD]
[TD="align: right"]1
[/TD]
[/TR]
[TR]
[TD]Old
[/TD]
[TD]Data 6
[/TD]
[TD]Data 13
[/TD]
[TD]Data 20
[/TD]
[TD]No
[/TD]
[TD="align: right"]2
[/TD]
[/TR]
[TR]
[TD]Old
[/TD]
[TD]Data 7
[/TD]
[TD]Data 14
[/TD]
[TD]Data 21
[/TD]
[TD]Yes
[/TD]
[TD="align: right"]6
[/TD]
[/TR]
</tbody>[/TABLE]
Below is my current code but only with update criteria. Hope you can help me. Thank you in advance.
Option Explicit
__________________________________________
Sub Test(ByVal sel As Range)
Dim cell As Range
Dim LastColumn As Long
LastColumn = Cells(1, Cells.Columns.Count).End(xlToLeft).Column
For Each cell In sel
Application.EnableEvents = False
If cell.Row > 8 And cell.Column > 1 And cell.Column < LastColumn + 1 Then
If Left(Cells(1, cell.Column), 5) = "Check" Then
GoTo A
Else
Cells(cell.Row, "A").Value = "Updated at " & Date
End If
End If
A:
Application.EnableEvents = True
Next cell
End Sub
I'm using MSExcel 2010.
Good day!
May I ask for your help? I'm having trouble in creating If statement with different criteria. The criteria are create, update and delete.
Created: Newly added data will be tagged as "Created + date it was created" on the "status" column
Updated: Existing data but you update something then it will be tagged as "Updated + date it was updated" on the "status" column
Deleted: If Column Test 4 was tagged as "No" then "status" column will be tagged as "Deleted + date it was deleted"
*Old - if no changes
The criteria will only be applied if changes made are not under the column with field name "Check".
Below is a sample scenario.
[TABLE="width: 492"]
<tbody>[TR]
[TD]Status
[/TD]
[TD]Test 1
[/TD]
[TD]Test 2
[/TD]
[TD]Test 3
[/TD]
[TD]Test 4
[/TD]
[TD]Check - XXXX
[/TD]
[/TR]
[TR]
[TD]Old
[/TD]
[TD]Data 1
[/TD]
[TD]Data 8
[/TD]
[TD]Data 15
[/TD]
[TD]Yes
[/TD]
[TD="align: right"]1
[/TD]
[/TR]
[TR]
[TD]Deleted
[/TD]
[TD]Data 2
[/TD]
[TD]Data 9
[/TD]
[TD]Data 16
[/TD]
[TD]No
[/TD]
[TD="align: right"]2
[/TD]
[/TR]
[TR]
[TD]Created
[/TD]
[TD]Data 3
[/TD]
[TD]Data 10
[/TD]
[TD]Data 17
[/TD]
[TD]Yes
[/TD]
[TD="align: right"]3
[/TD]
[/TR]
[TR]
[TD]Updated
[/TD]
[TD]Data 4
[/TD]
[TD]Data 11
[/TD]
[TD]Data 18
[/TD]
[TD]Yes
[/TD]
[TD="align: right"]4
[/TD]
[/TR]
[TR]
[TD]Old
[/TD]
[TD]Data 5
[/TD]
[TD]Data 12
[/TD]
[TD]Data 19
[/TD]
[TD]No
[/TD]
[TD="align: right"]1
[/TD]
[/TR]
[TR]
[TD]Old
[/TD]
[TD]Data 6
[/TD]
[TD]Data 13
[/TD]
[TD]Data 20
[/TD]
[TD]No
[/TD]
[TD="align: right"]2
[/TD]
[/TR]
[TR]
[TD]Old
[/TD]
[TD]Data 7
[/TD]
[TD]Data 14
[/TD]
[TD]Data 21
[/TD]
[TD]Yes
[/TD]
[TD="align: right"]6
[/TD]
[/TR]
</tbody>[/TABLE]
Below is my current code but only with update criteria. Hope you can help me. Thank you in advance.
Option Explicit
__________________________________________
Sub Test(ByVal sel As Range)
Dim cell As Range
Dim LastColumn As Long
LastColumn = Cells(1, Cells.Columns.Count).End(xlToLeft).Column
For Each cell In sel
Application.EnableEvents = False
If cell.Row > 8 And cell.Column > 1 And cell.Column < LastColumn + 1 Then
If Left(Cells(1, cell.Column), 5) = "Check" Then
GoTo A
Else
Cells(cell.Row, "A").Value = "Updated at " & Date
End If
End If
A:
Application.EnableEvents = True
Next cell
End Sub
I'm using MSExcel 2010.
Last edited: