kimberly090
Board Regular
- Joined
- May 22, 2014
- Messages
- 99
Hi,
I have 4 sheet in my excel file,
I wish that when column O value in Overall sheet is equal to Ni, it will copy the row to Ni sheet
When column O value in Overall sheet is equal to NiAu, it will copy the row to NiAu sheet.
When column O value in Overall sheet is equal to NiPd, it will copy the row to NiPd sheet.
I have my code at below, but once I add in new row in my Overall sheet, it will keep duplicate the whole data in the Ni,NiAu,NiPd sheet.
I wish it will only copy the last row when there is new entry inside Overall page.
As below will be my code:
I have 4 sheet in my excel file,
I wish that when column O value in Overall sheet is equal to Ni, it will copy the row to Ni sheet
When column O value in Overall sheet is equal to NiAu, it will copy the row to NiAu sheet.
When column O value in Overall sheet is equal to NiPd, it will copy the row to NiPd sheet.
I have my code at below, but once I add in new row in my Overall sheet, it will keep duplicate the whole data in the Ni,NiAu,NiPd sheet.
I wish it will only copy the last row when there is new entry inside Overall page.
As below will be my code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)Dim lr As Long, lr2 As Long, lr3 As Long, lr4 As Long, r As Long
lr = Sheets("Overall").Cells(Rows.Count, "A").End(xlUp).Row
lr2 = Sheets("Ni").Cells(Rows.Count, "A").End(xlUp).Row
lr3 = Sheets("NiAu").Cells(Rows.Count, "A").End(xlUp).Row
lr4 = Sheets("NiPd").Cells(Rows.Count, "A").End(xlUp).Row
For r = lr To 2 Step -1
Select Case Range("O" & r).Value
Case Is = "Ni"
Rows(r).Copy Destination:=Sheets("Ni").Range("A" & lr2 + 1)
lr2 = Sheets("Ni").Cells(Rows.Count, "A").End(xlUp).Row
Case Is = "NiAu"
Rows(r).Copy Destination:=Sheets("NiAu").Range("A" & lr3 + 1)
lr3 = Sheets("NiAu").Cells(Rows.Count, "A").End(xlUp).Row
Case Is = "NiPd"
Rows(r).Copy Destination:=Sheets("NiPd").Range("A" & lr4 + 1)
lr4 = Sheets("NiPd").Cells(Rows.Count, "A").End(xlUp).Row
End Select
Next r
End Sub