Macro to run from selection made using data validation list

Posted on 2016-08-17
Medium Priority
Last Modified: 2016-08-18
Hi Experts Using Excel 2013

i have the following vba code which may need tidying up (see below)

i want to run the below macro based on the data validation list in cell B3 worksheet "Overall". I also want to remove any blank rows in the data set after the duplication element has been removed.

Sub CopyandPasteValues()

    Sheets("Unique List").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    ActiveSheet.Range("$A$1:$B$1928").RemoveDuplicates Columns:=Array(1, 2), _
    Range("Table_ExternalData_18[[#Headers],[IFA First Name]]").Select

End Sub

Open in new window

Question by:route217
  • 2
LVL 23

Accepted Solution

Roy Cox earned 2000 total points
ID: 41760573
There's no indication what the Data Validation list is or what it is supposed to do. Provide more information and a sample workbook.

This code is more efficient
Option Explicit

Sub CopyandPasteValues()
''/// assumes Sheets("Data") is the sheet to copy from
''/// if not use ActiveSheet
    Sheets("Unique List").Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                                                                                          :=False, Transpose:=False
    Application.CutCopyMode = False
    Sheets("Unique List").Range("$A$1:$B$1928").RemoveDuplicates Columns:=Array(1, 2), _
    ''///  I see no point in this. Is Data the starting point? If so then my code does not
    ''///change sheets so you can delete this
    '    Sheets("Data").Select
    '    Range("Table_ExternalData_18[[#Headers],[IFA First Name]]").Select

End Sub

Open in new window


Author Comment

ID: 41760588
thanks for the feedback...
LVL 23

Expert Comment

by:Roy Cox
ID: 41761263
Pleased to help

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question