why this code is showing in red any one correct this

Prasad K

Board Regular
Joined
Aug 4, 2021
Messages
189
Office Version
  1. 2016
  2. 2007
Platform
  1. Windows
any one correct this code


VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheet1.Range("A2:A" & Sheet1.Range("A" & Rows.Count).End(xlUp).Row).Copy _Destination:=Sheet2.Range("A2:A" & Rows.Count).End(xlUp).Offset(1, 0)
Sheet2.Range("A2", Sheet2.Range("A" & Rows.Count).End(xlUp)).RemoveDuplicates 1
End Sub
 

Attachments

  • s1.JPG
    s1.JPG
    36.4 KB · Views: 7

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try
VBA Code:
Sheet1.Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row).Copy Sheet2.Range("A2:A" & Rows.Count).End(xlUp).Offset(1, 0)
Sheet2.Range("A2", Sheet2.Range("A" & Rows.Count).End(xlUp)).RemoveDuplicates 1
 
Upvote 0
Try
VBA Code:
Sheet1.Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row).Copy Sheet2.Range("A2:A" & Rows.Count).End(xlUp).Offset(1, 0)
Sheet2.Range("A2", Sheet2.Range("A" & Rows.Count).End(xlUp)).RemoveDuplicates 1
Thank you it's working perfectly & one more small change in this code remove duplicates on entire row in sheet2
 
Upvote 0
Thank you it's working perfectly & one more small change in this code remove duplicates on entire row in sheet2

remove entire row in sheet2


dup.xlsm
ABCD
1Emp idEmp NameEmp GenderEmp Salary
2101anilmale12000
3102arunmale12000
4103swethafemale12000
5101anilmale12000
Sheet1



dup.xlsm
ABCD
1Emp idEmp NameEmp GenderEmp Salary
2101anilmale12000
3102arunmale12000
4103swethafemale12000
5anilmale12000
Sheet2




VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
Sheet1.Range("A2:D" & Range("A" & Rows.Count).End(xlUp).Row).Copy Sheet2.Range("A2:D" & Rows.Count).End(xlUp).Offset(1, 0)
Sheet2.Range("A2", Sheet2.Range("A" & Rows.Count).End(xlUp)).RemoveDuplicates 1
End Sub
 
Upvote 0
remove entire row in sheet2


dup.xlsm
ABCD
1Emp idEmp NameEmp GenderEmp Salary
2101anilmale12000
3102arunmale12000
4103swethafemale12000
5101anilmale12000
Sheet1



dup.xlsm
ABCD
1Emp idEmp NameEmp GenderEmp Salary
2101anilmale12000
3102arunmale12000
4103swethafemale12000
5anilmale12000
Sheet2




VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
Sheet1.Range("A2:D" & Range("A" & Rows.Count).End(xlUp).Row).Copy Sheet2.Range("A2:D" & Rows.Count).End(xlUp).Offset(1, 0)
Sheet2.Range("A2", Sheet2.Range("A" & Rows.Count).End(xlUp)).RemoveDuplicates 1
End Sub
Egnore this i got answer to delete entire row in sheet2

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
Sheet1.Range("A2:D" & Range("A" & Rows.Count).End(xlUp).Row).Copy Sheet2.Range("A2:D" & Rows.Count).End(xlUp).Offset(1, 0)
Sheet2.Range("A2", Sheet2.Range("D" & Rows.Count).End(xlUp)).RemoveDuplicates 1
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,877
Messages
6,122,051
Members
449,064
Latest member
scottdog129

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top