Macro to run from selection made using data validation list

Posted on 2016-08-17
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 17

Accepted Solution

Roy_Cox earned 500 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 17

Expert Comment

ID: 41761263
Pleased to help

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

930 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now