Hi all
I'm completely new in the forums world. I did a little bit of vba many years ago and now I have been task with something impossible for me but I hope it will be easy for you experts.
Firs I need to say that I have posted this thread in other forums and I will provide links but I have not yet found a solution. I didn't mean to cross-post and I have been found out but I did it unintentionally and have already apologise in the other forums so I hope you will still help me.
My initial post was solved but a question arising from it has not been solved yet so I'm trying this forum to see if any of you are interested and find a solution. I certainly would appreciate it.
Original question was to copy specific cells from sheet 1 to sheet 2 when a condition on sheet 1 was met by selectin one choice of a dropdown menu. That code produced by a forum expert worked perfectly. But, when the condition changed on sheet 1 and didn't meet the pre-requisite to be copied in sheet 2 but had already been copied because the pre-requisite had been previously chosen and met, that row was not deleted from sheet 2, thus making the data inaccurate. I hope I explain myself well, otherwise ask me please.
So another forum expert came up with a brilliant solution, which is to automatically create a unique identifier with date and time and place it in column XX. Unfortunately when I copy this code it doesn't work for me and doesn't even copy the specific cells on sheet 2. Legend is on sheet 3.
I post the code below and attach the spreadsheet to see if some of you can spot why it doesn't work for me. I would greatly appreciate help to solve this.
[Private Sub Worksheet_Change(ByVal Target As Range)
'Modified 1-5-2018 1:30 PM EST
On Error GoTo M
If Target.Count > 1 Then Exit Sub
Dim c As Range
Dim Lastrow As Long
Lastrow = Sheets("Costing").Cells(Rows.Count, "XX").End(xlUp).Row + 1
If Target.Column = 12 And Target.Value = "Exit from business or transfer to another role outside current BU or Function - no backfill" Then
Cells(Target.Row, "XX").Value = Now()
Range(Cells(Target.Row, 1), Cells(Target.Row, "H")).Copy Sheets("Costing").Cells(Lastrow, 1)
Sheets("Costing").Cells(Lastrow, "XX").Value = Now()
Else
If Target.Column = 12 And Target.Value <> "Exit from business or transfer to another role outside current BU or Function - no backfill" Then
For Each c In Sheets("Costing").Range("XX1:XX" & Lastrow)
If c.Value = Cells(Target.Row, "XX").Value Then Sheets("Costing").Rows(c.Row).Delete
Next
Cells(Target.Row, "XX").Value = ""
End If
End If
Exit Sub
M:
MsgBox "Sorry we had some type problem. Try again"
End Sub]
The link with relevant thread is https://www.mrexcel.com/forum/excel...t4981259.html?t=1037655&p=4981259#post4981259
Please note that I made a test spreadsheet, so the name for sheets and text to select copying cells are different in this thread. But the code doesn't work in my test spreadsheet either, so I thought I would post the real spreadsheet to avoid any more chances to errors.
Both spreadsheets attached, test and real
thank you and I hope you can help
I'm completely new in the forums world. I did a little bit of vba many years ago and now I have been task with something impossible for me but I hope it will be easy for you experts.
Firs I need to say that I have posted this thread in other forums and I will provide links but I have not yet found a solution. I didn't mean to cross-post and I have been found out but I did it unintentionally and have already apologise in the other forums so I hope you will still help me.
My initial post was solved but a question arising from it has not been solved yet so I'm trying this forum to see if any of you are interested and find a solution. I certainly would appreciate it.
Original question was to copy specific cells from sheet 1 to sheet 2 when a condition on sheet 1 was met by selectin one choice of a dropdown menu. That code produced by a forum expert worked perfectly. But, when the condition changed on sheet 1 and didn't meet the pre-requisite to be copied in sheet 2 but had already been copied because the pre-requisite had been previously chosen and met, that row was not deleted from sheet 2, thus making the data inaccurate. I hope I explain myself well, otherwise ask me please.
So another forum expert came up with a brilliant solution, which is to automatically create a unique identifier with date and time and place it in column XX. Unfortunately when I copy this code it doesn't work for me and doesn't even copy the specific cells on sheet 2. Legend is on sheet 3.
I post the code below and attach the spreadsheet to see if some of you can spot why it doesn't work for me. I would greatly appreciate help to solve this.
[Private Sub Worksheet_Change(ByVal Target As Range)
'Modified 1-5-2018 1:30 PM EST
On Error GoTo M
If Target.Count > 1 Then Exit Sub
Dim c As Range
Dim Lastrow As Long
Lastrow = Sheets("Costing").Cells(Rows.Count, "XX").End(xlUp).Row + 1
If Target.Column = 12 And Target.Value = "Exit from business or transfer to another role outside current BU or Function - no backfill" Then
Cells(Target.Row, "XX").Value = Now()
Range(Cells(Target.Row, 1), Cells(Target.Row, "H")).Copy Sheets("Costing").Cells(Lastrow, 1)
Sheets("Costing").Cells(Lastrow, "XX").Value = Now()
Else
If Target.Column = 12 And Target.Value <> "Exit from business or transfer to another role outside current BU or Function - no backfill" Then
For Each c In Sheets("Costing").Range("XX1:XX" & Lastrow)
If c.Value = Cells(Target.Row, "XX").Value Then Sheets("Costing").Rows(c.Row).Delete
Next
Cells(Target.Row, "XX").Value = ""
End If
End If
Exit Sub
M:
MsgBox "Sorry we had some type problem. Try again"
End Sub]
The link with relevant thread is https://www.mrexcel.com/forum/excel...t4981259.html?t=1037655&p=4981259#post4981259
Please note that I made a test spreadsheet, so the name for sheets and text to select copying cells are different in this thread. But the code doesn't work in my test spreadsheet either, so I thought I would post the real spreadsheet to avoid any more chances to errors.
Both spreadsheets attached, test and real
thank you and I hope you can help