Hi, I have a Spreadsheet that I use to control my business finances. I have implemented some VBA code to make the Spreadsheet copy an entire row from one sheet to another when a certain value is entered on a cell (all with help from forums, I have never used VBA before and I have very few experience in programing).
I've also implemented some code to make the Spreadsheet auto fill dates in some cells and an Unique ID on the 'column A' cell of each row as son as any value is entered in any cell of that roll.
Now what I need to do is to create some code to make it check for this Unique ID before copying the entire row and if it finds the ID in the target Sheet it should copy the row overwriting the original, if not just copy in the first empty row (as it already does). This way, if I have to modify some value in a row that have already been copied to the target Sheet it will update the row in the target sheet instead of copying again (thats what the code is doing now).
Here is my code:
Thanks in advance for any help.
I've also implemented some code to make the Spreadsheet auto fill dates in some cells and an Unique ID on the 'column A' cell of each row as son as any value is entered in any cell of that roll.
Now what I need to do is to create some code to make it check for this Unique ID before copying the entire row and if it finds the ID in the target Sheet it should copy the row overwriting the original, if not just copy in the first empty row (as it already does). This way, if I have to modify some value in a row that have already been copied to the target Sheet it will update the row in the target sheet instead of copying again (thats what the code is doing now).
Here is my code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Insert date on column 'J' when data entered in column 'K':
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Range("K:K"), .Cells) Is Nothing Then
Application.EnableEvents = False
With .Offset(0, -1)
If .Value = "" Then
.NumberFormat = "dd/mm/yy"
.Value = Date
End If
End With
Application.EnableEvents = True
End If
End With
'Insert date on column 'B' and ID on column 'A' when data entered in any cell of the row:
With Target
If .Count > 1 Then Exit Sub
Application.EnableEvents = False
With Range("B" & Target.Row)
If .Value = "" Then
.NumberFormat = "dd/mm/yy"
.Value = Date
End If
With Range("A" & Target.Row)
If .Value = "" Then
.FormulaR1C1 = "=R[-1]C+1"
End If
End With
End With
Application.EnableEvents = True
End With
'Copy row to personal Sheet when name is entered in column 'K':
Dim rng1 As Range
Dim rng2 As Range
Dim rng3 As Range
Set rng1 = Target.EntireRow
Set rng2 = Worksheets("Eduardo").Cells(Rows.Count, 1).End(xlUp) _
.Offset(1, 0)
Set rng3 = Worksheets("Junior").Cells(Rows.Count, 1).End(xlUp) _
.Offset(1, 0)
If Target.Column = 11 Then
On Error GoTo endit
Application.EnableEvents = False
If Target.Value = "Eduardo" Then
With rng1
.Copy Destination:=rng2
End With
End If
If Target.Value = "Junior" Then
With rng1
.Copy Destination:=rng3
End With
End If
End If
endit:
Application.EnableEvents = True
End Sub
Thanks in advance for any help.