VBA Code

stopgyal

New Member
Joined
Aug 14, 2015
Messages
15
Hi everyone,
I am new to VBA and still trying to get my head around VBA coding. Any help will be much appreciated.

I want to copy and paste the values from range (S19:S29) to range (E56:E66), if any change happens to range (S19:S29). Then I want to remove the duplicate in range (S19:S29), so I can create a drop-down list of unique values. The code I created is as below:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address(0, 0) = "S19:S29" Then Range("S19:S29").Copy
ActiveSheet.Paste Destination:=Worksheets("WorkSheet1").Range("E56:E66")
ActiveSheet.Range("E56:E66").RemoveDuplicates Columns:=5, Header:=xlYes

End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
welcome to the forum. please use code tags when pasting your code.
# button inserts code tags...


try like:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Target, Range("S19:S29")) Is Nothing Then
        Range("S19:S29").Copy Destination:=Range("E56:E66")
    End If
    Range("E56:E66").RemoveDuplicates Columns:=5, Header:=xlYes

End Sub
 
Upvote 0
Apologise for not using the code tags. I used the code you provided, but nothing is happening and I am not sure why.
 
Upvote 0
below worked for me:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("S19:S29")) Is Nothing Then Exit Sub
    Range("S19:S29").Copy Destination:=Range("E56:E66")
    Range("E56:E66").RemoveDuplicates Columns:=1, Header:=xlYes
End Sub
 
Upvote 0
Thanks for your help, it worked perfectly worked when applied to normal cells. But it doesn't work when the cells (S19:S29) is relatively referenced to another cells. Any advice on that please.
 
Upvote 0
you are welcome.

i am still learning. :)

but there are 'supernovas' here and on other communties. :)
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

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