Меню

You cannot remove duplicate information when the range has an outline ошибка

I’m trying to remove duplicates in excel 2013 VBA. but I’m getting error «object does not support this property or method». The problem is I don’t have static range to select. I want remove duplicates from the column heaader ‘abcd’.

Cells.Find(what:="abcd").Activate
ActiveCell.EntireColumn.Select
Set rng = Selection
ActiveSheet.rng.RemoveDuplicates

asked Jul 25, 2015 at 21:17

Hideandseek's user avatar

2

You need to tell the Range.RemoveDuplicates method what column to use. Additionally, since you have expressed that you have a header row, you should tell the .RemoveDuplicates method that.

Sub dedupe_abcd()
    Dim icol As Long

    With Sheets("Sheet1")   '<-set this worksheet reference properly!
        icol = Application.Match("abcd", .Rows(1), 0)
        With .Cells(1, 1).CurrentRegion
            .RemoveDuplicates Columns:=icol, Header:=xlYes
        End With
    End With
End Sub

Your original code seemed to want to remove duplicates from a single column while ignoring surrounding data. That scenario is atypical and I’ve included the surrounding data so that the .RemoveDuplicates process does not scramble your data. Post back a comment if you truly wanted to isolate the RemoveDuplicates process to a single column.

answered Jul 25, 2015 at 22:40

6

To remove duplicates from a single column

 Sub removeDuplicate()
 'removeDuplicate Macro
 Columns("A:A").Select
 ActiveSheet.Range("$A$1:$A$117").RemoveDuplicates Columns:=Array(1), _ 
 Header:=xlNo 
 Range("A1").Select
 End Sub

if you have header then use Header:=xlYes

Increase your range as per your requirement.
you can make it to 1000 like this :

ActiveSheet.Range("$A$1:$A$1000")

More info here here

Community's user avatar

answered Jul 25, 2015 at 22:56

mahi_0707's user avatar

mahi_0707mahi_0707

1,0209 silver badges17 bronze badges

If you got only one column in the range to clean, just add «(1)» to the end. It indicates in wich column of the range Excel will remove the duplicates.
Something like:

 Sub norepeat()

    Range("C8:C16").RemoveDuplicates (1)

End Sub

Regards

answered Feb 25, 2021 at 20:25

Jorge Jorge's user avatar

OUTLINE EXCEL DATA IN MICROSOFT EXCEL – INSTRUCTIONS

outline-excel-data-in-microsoft-excel-instructions image

To outline Excel data by applying an outline to a selected cell range, first select the cell range to outline. Then click the “Group” button in the “Outline” group on the “Data” tab in the Ribbon to launch …
From teachucomp.com
Estimated Reading Time 6 mins


HOW TO REMOVE THE OUTLINE OF A TEXT BOX IN EXCEL — YOUTUBE

how-to-remove-the-outline-of-a-text-box-in-excel-youtube image

https://www.youtube.com/channel/UCmV5uZQcAXUW7s4j7rM0POg?sub_confirmation=1How to remove the outline of a text box in Excel
From youtube.com
Author Vishap TVplus
Views 3.7K


HOW TO GROUP AND OUTLINE EXCEL DATA: 14 STEPS (WITH PICTURES)

Part 1Part 1 of 2:Outlining Automatically Download Article. Open your Excel document. Double-click the Excel document to open it. Click the Data tab. It’s in the left side of the green ribbon that’s at the top of the Excel window. Doing so will open a toolbar below the ribbon. Click the bottom of the Group button.
From wikihow.com
Views 1.5M


HOW DO I REMOVE OUTLINE FROM AN EXCEL WORKSHEET?

To remove the Outline. Just click your cursor anywhere on your worksheet. Select Data menu, Group and Outline, choose Clear Outline. Your worksheet data will return to exactly as it was before you created the original outline. We cover this topic on our Intermediate course, please check our syllabus for more details.
From stl-training.co.uk
4.8/5


CLEAR EXCEL CELL CONTENTS — OZGRID

Lesson 28 — Excel: The Different Methods of Clearing Cell Contents << PREVIOUS LESSON |NEXT LESSON>> | BACK TO EXCEL LEVEL 1 TRAINING INDEX THE DIFFERENT METHODS OF CLEARING EXCEL CELL CONTENTS. Normally when working in Excel, if we want to remove a cell(s) contents we would simply push the Delete key on our keyboard. This would …
From ozgrid.com


10 SUPER NEAT WAYS TO CLEAN DATA IN EXCEL SPREADSHEETS

Go to Home –> Clear –> Clear Formats; Similarly, you can also clear only the comments, hyperlinks, or content. #10 Use Find and Replace to Clean Data in Excel. Find and replace is indispensable when it comes to data cleansing. For example, you can select and remove all zeros, change references in formulas, find and change formatting, and so on.
From trumpexcel.com


CLEAR CELLS OF CONTENTS OR FORMATS — SUPPORT.MICROSOFT.COM

Select the cells, rows, or columns that you want to clear. Tip: To cancel a selection of cells, click any cell on the worksheet. On the Home tab, in the Editing group, click the arrow next to the Clear button , and then do one of the following: To clear all contents, formats, and comments that are contained in the selected cells, click Clear All.
From support.microsoft.com


OUTLINES IN EXCEL: HOW TO CREATE AN OUTLINE — STUDY.COM

Go to the Data menu in the ribbon. Look in the Outline grouping of commands. Click on the group command. Select Auto Outline. Notice the outline window, which opened on the left-hand side of the …
From study.com


REMOVE GRIDLINES FROM A WORKSHEET IN EXCEL — TEACHMSOFFICE.COM

Microsoft Office Excel: Clear All Formatting from Cells with One Mouse Click: 2:27: Microsoft Office Excel: Remove Comments from an Entire Worksheet with One Mouse Click: 2:30 : Microsoft Office Excel: Select All Cells that Contain Formulas and Functions: 2:22: Microsoft Office Excel: Remain in the Same Cell After Hitting Enter: 2:08: Microsoft Office Excel: …
From teachmsoffice.com


HOW TO USE TEMPLATES AND OUTLINES IN EXCEL 2013

Click the Add button. Enter a name for the view in the Name box. Now go to Include In View and select the settings that you want to include. Click OK. To apply a custom view, click the View tab again, then click Custom Views. Select the name of your view in the Custom Views dialogue box. Click the Show button.
From universalclass.com


HOW TO SHOW OR HIDE OUTLINE SYMBOLS IN EXCEL? — EXTENDOFFICE

1. Click Kutools > Show / Hide > View Options, see screenshot: 2. In the View Options dialog box, under the Window options section, check or uncheck the Outline symbols to show or hide the outline symbols. If you want to apply this function to the whole workbook, you can click Apply to all sheets button at the bottom of the dialog box.
From extendoffice.com


CLEAR FORMATTING IN EXCEL: HOW TO REMOVE ALL FORMATS IN A …

To do this, perform the following steps: In your Excel worksheet, click File > Options, and then select Quick Access Toolbar on the left-side pane. Under Choose commands from, select All Commands. In the list of commands, scroll down to Clear Formats, select it and click the Add button to move it to the right-hand section. Click OK.
From ablebits.com


REMOVING DUPLICATES — RANGE HAS AN «OUTLINE»

«You cannot remove duplicate information when the range has an outline. To remove duplicates, clear the outline and perform the remove duplicates operation again.» To remove duplicates, clear the outline and perform the remove duplicates operation again.»
From answers.microsoft.com


HOW TO REMOVE TABLE FORMATTING IN EXCEL (2 SMART WAYS)

First, select the entire table. After this press on to the Home tab and in the Editing section of Home tab look for the Clear option. After selecting the Clear option, you will get a drop-down list. From there, select the Clear Formats option. After pressing the Clear Formats option, you will see all the colors from your table is gone and it …
From exceldemy.com


UNDERSTANDING SOME ADVANCED FEATURES OF EXCEL 2016: OUTLINES, …

1. A worksheet can only contain one outline. 2. Outlines can either be created manually or automatically. 3. An outline can be created for an entire worksheet or just for a range of data. 4. You can hide the outline symbols without removing the outline. Simply press CTRL+8 to toggle the symbols off and on.
From universalclass.com


CLEAROUTLINE METHOD [EXCEL 2003 VBA LANGUAGE REFERENCE]

In this article. Example. Clears the outline for the specified range. expression **.ClearOutline**. expression Required. An expression that returns a Range object.
From docs.microsoft.com


HOW TO CLEAR ENTIRE SHEET OR SPECIFIED RANGE IN EXCEL?

1. Open the worksheet you will clear specified range from, then press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window. 2. In the Microsoft Visual Basic for Applications window, click Insert > Module, and then copy below VBA code into the Module. Clear range but retain the formatting, please try this code.
From extendoffice.com


EXCEL VBA 2007 — HOW TO CLEAR HORIZONTAL OUTLINE

Heya, I’ve got a worksheet that has data arranged with both horizontal and vertical grouping. When certain conditions are met, I want to clear the horizontal outlining using VBA. The line which I want to ungroup is selected. Using «Selection.Clearoutline» will remove the horizontal grouping, but will also remove the vertical grouping.
From social.msdn.microsoft.com


RANGE.CLEAROUTLINE METHOD (EXCEL) | MICROSOFT DOCS

Clears the outline for the specified range. Syntax. expression.ClearOutline. expression A variable that represents a Range object. Return value. Variant. Example. This example clears the outline for the range A1:G37 on Sheet1. Worksheets(«Sheet1»).Range(«A1:G37»).ClearOutline Support and feedback. Have questions …
From docs.microsoft.com


ADDING THE AUTO OUTLINE, CLEAR OUTLINE, AND SHOW OUTLINE

1. Place the mouse arrow over one of the toolbars, right-click, and then select Customize from the shortcut menu. 2. Select the Commands tab. 3. From Data, drag the appropriate icons to the Standard toolbar. Screenshot // Adding the Auto Outline, Clear Outline, and Show Outline Symbols Icons to the Toolbar. Previous.
From exceltip.com


OUTLINING DATA IN EXCEL — COLLAPSE IN EASY STEPS

Outlining Data. Outlining data makes your data easier to view. In this example we will total rows of related data and collapse a group of columns. 1. First, sort the data on the Company column. 2. On the Data tab, in the Outline group, click Subtotal. 3. Select the Company column, the column we use to outline our worksheet.
From excel-easy.com


IF OUTLINE EXISTS REMOVE IT IN VBA — MREXCEL MESSAGE BOARD

Adding the removal code you posted at the beginning of the other sample code will clear any old outlining. Code: Sub AutoGroup () ‘Remove any Outlining on worksheet Cells.ClearOutline ‘Begin new Outlining Range («B2»).Select Do Until ActiveCell = «» And ActiveCell.Offset (1, 0) = «» If ActiveCell.Offset (0, -1) <> «» Then SR = ActiveCell.Offset …
From mrexcel.com


EXCEL 2010: OUTLINING DATA — GCFGLOBAL.ORG

Select the Data tab, then locate the Outline group. Click the Subtotal command to open the Subtotal dialog box. Opening the Subtotal dialog box. In the At each change in field, select the column you want to use to outline your worksheet. In this example, we’ll choose T-Shirt Size.
From edu.gcfglobal.org


HOW TO REMOVE TABLE FORMATTING IN EXCEL (EASY GUIDE)

To remove all the formatting, follow the below steps: Select the entire range that has the formatting. Click the Home tab. In the Editing group, click on Clear. In the options that show up, click on Clear Formats. This would leave you with only …
From trumpexcel.com


HOW TO CLEAR CONTENTS IN EXCEL WITHOUT DELETING FORMULAS

Below are the steps to clear the content from these cells while leaving the formulas untouched: Press the F5 key. This will open the ‘Go-To’ dialog box. Click on the ‘Special’ button. This will open the ‘Go-To Special’ dialog box. Click OK. The above steps would select only those cells that have values in it.
From spreadsheetplanet.com


THREE KEYBOARD SHORTCUTS TO CLEAR ALL IN EXCEL

Here are three keyboard shortcuts you can use to clear all including data, formatting, comments, etc. from a data range: – Ctrl + Home – This will take you to the upper left corner of your worksheet. – Ctrl + Shift + Right Arrow – this will highlight the top row of your data range. While still holding the Ctrl + Shift keys, hit the Down …
From excel-bytes.com


CLEANING DATA WITH EXCEL’S CLEAN FORMULA | MYEXCELONLINE

What it means: =CLEAN ( this dirty text cell) There are times when imported text from other applications contain characters that are unprintable. The CLEAN formula in Excel can clean up the unprintable characters easily. This is how it is done below (go to the bottom of the page if you want to see the animated gif tutorial):
From myexcelonline.com


HOW DO I CLEAR EXCEL CONTENT WITHOUT REMOVING FORMULA

It will clear cells that do not have formulas. Macros are very easy to install and use: 1. ALT-F11 brings up the VBE window. 2. ALT-I. ALT-M opens a fresh module. 3. paste the stuff in and close the VBE window. If you save the workbook, the macro will be saved with it.
From answers.microsoft.com


HOW TO SHOW GRIDLINES IN EXCEL; HIDE (REMOVE) LINES

Go to the Font group on the HOME tab and open the Fill Color drop-down list. Choose the white color from the list to remove gridlines. Note: If you want to show lines in Excel, pick the No Fill option. As you can see in the screenshot above, applying the white background will give an effect of hidden gridlines in your worksheet.
From ablebits.com


HOW TO CLEAR EXCEL FORMATTING IN A SNAP + AMAZING SHORTCUT

To do so, let’s select all cells in the worksheet by pressing ‘Ctrl’ + ‘A’. The ‘Clear Format’ tool is located in the ‘Home’ tab. So make sure you’re on the right tab. The tool is on the ‘Editing’ group of the tab. Click the ‘Clear’ icon and choose ‘Clear Formats’ from the dropdown list.
From spreadsheeto.com


EXCEL TEXT BOX OVERLAY- WHAT IS IT, HOW TO REMOVE?

And I can type about 140 characters into this box. Deleting surrounding rows or columns does not affect the box, so it doesn’t appear to be correlated to a specific cell. There is no context sensitive help when in the box and almost all normal excel functions are greyed out when I’m in it. Any help is appreciated.
From techcommunity.microsoft.com


REMOVE FORMATTING FOR EACH CELL IN RANGE — AUTOMATE EXCEL

Clear Formats From a Range of Cells. This will clear Cell Formatting for Range A1:C1. 1. 2. 3. Sub ClearFormats() Range(«A1:C1»).ClearFormats. End Sub. If you’d like to clear the formatting of an entire worksheet, use the Cells Object instead:
From automateexcel.com


EXCEL CLEAR CONTENTS, FORMATS, OR ENTIRE CELL SHORTCUT — AUTOMATE …

Clear All. This Excel Shortcut clears everything (content, formats, comments, and hyperlinks) from the selected cell (s). PC Shorcut: ALT > H > E > A. Remember This Shortcut: PC: Alt is the command to activate the Ribbon shortcuts. H for H ome, E for Cl e ar, A for A ll.
From automateexcel.com


HOW TO HIDE COMMENTS, FORMULAS, OVERFLOW TEXT, AND GRIDLINES IN …

Select “Format Cells” from the popup menu. NOTE: You can select multiple cells and hide the formulas for all the selected cells. Click the “Protection” tab on the “Format Cells” dialog box, and select the “Hidden” check box so there is a check mark in the box. Click “OK” to accept the change and close the dialog box.
From howtogeek.com


HOW TO REMOVE OUTLINE OF TEXT BOX IN EXCEL SHEET — YOUTUBE

About Press Copyright Contact us Creators Advertise Developers Terms Privacy Policy & Safety How YouTube works Test new features Press Copyright Contact us Creators …
From youtube.com


HOW TO CREATE AN AUTOMATIC OUTLINE IN THE MICROSOFT EXCEL WITH …

The Corporate Training is suitable for Corporate Bodies, Institutes, Colleges, Universities, Training Centers, Tutors, Entrepreneurs, Resellers. Train Your Staffs and Grow Your Business, Train Your Students and Charge Your Own Price. Read more
From siit.co


QUICKLY CLEAR DATA ENTRY CELLS IN EXCEL – CONTEXTURES BLOG

For example, in this order form, information is entered in the green cells. Name those cells, and you can quickly clear them before starting the next order. Select all the green cells, and name the range DataEntry. Click the arrow at the right of the Name Box, and click on DataEntry. With all the data entry cells selected, press the Delete key …
From contexturesblog.com


UNDERSTANDING OUTLINING (MICROSOFT EXCEL) — EXCELTIPS (RIBBON)

Select a cell in a data list, then display the Data tab of the ribbon. Click on Subtotal in the Outline group. Let Excel automatically outline your data list. Select the list that you want outlined, then display the Data tab of the ribbon. Click Group from the Outline group, then click Auto Outline. Manually outline your data list.
From excelribbon.tips.net


HOW TO CLEAR FORMATTING FROM AN EXCEL SPREADSHEET — EXCELCHAT

1. If we want to remove all current formatting from a range of cells or the entire worksheet, we can follow these steps. We will highlight the cells we want to format. Figure 2 – How to clear formatting. In the Home tab, we will navigate to the Editing group and click the arrow next to the Clear button. Next, we will select Clear Formats.
From got-it.ai


Удаление дубликатов

monstr_ork

Дата: Вторник, 20.02.2018, 22:46 |
Сообщение № 1

Группа: Проверенные

Ранг: Форумчанин

Сообщений: 133


Репутация:

0

±

Замечаний:
0% ±


Excel 2016

Добрый вечер!
Подскажите пожалуйста. почему функция удаления дубликатов не работает, если ее записать через макроредер.
Код макроса и файл как пример

 

Ответить

InExSu

Дата: Вторник, 20.02.2018, 22:59 |
Сообщение № 2

Группа: Друзья

Ранг: Ветеран

Сообщений: 646


Репутация:

96

±

Замечаний:
0% ±


Excel 2010

Привет!
Хватит одной строки
[vba]

Код

    ActiveSheet.Range(«Таблица1»).RemoveDuplicates Columns:=1, Header:= _
        xlYes

[/vba]


Разработчик Битрикс24 php, Google Apps Script, VBA Excel

 

Ответить

Апострофф

Дата: Вторник, 20.02.2018, 23:00 |
Сообщение № 3

Группа: Проверенные

Ранг: Обитатель

Сообщений: 416


Репутация:

117

±

Замечаний:
0% ±


Excel 1997

monstr_ork, а если так-
[vba]

Код

ActiveSheet.Range(«Таблица1»).RemoveDuplicates Columns:=1, Header:=xlYes

[/vba]

 

Ответить

monstr_ork

Дата: Вторник, 20.02.2018, 23:09 |
Сообщение № 4

Группа: Проверенные

Ранг: Форумчанин

Сообщений: 133


Репутация:

0

±

Замечаний:
0% ±


Excel 2016

monstr_ork, а если так-
ActiveSheet.Range(«Таблица1»).RemoveDuplicates Columns:=1, Header:=xlYes

Все работает, хотелось бы уточнить если Вы знаете, а с чем связано, что макрорекодер не правильно записал код?

 

Ответить

  1. 10-21-2019, 01:21 PM


    #1

    Vitae is offline


    Registered User


    «Remove Duplicates» not working despite «Conditional Formatting» finding the dupes

    Using Office 2016
    Columns A/B are using Conditional Formatting and displaying the Duplicates.
    Columns D/E are the exact same paste from the exact same source, pasted in as «Values»
    I’ve pasted from Excel to Excel. Notepad to Excel. Wordpad to Excel. Word to Excel. Always doing the paste as Values.
    A/B works and highlights the Dupes, but when I try «Remove Duplicates» on D/E (or A/B) it always says that there are «No duplicate values found»


  2. 10-21-2019, 01:26 PM


    #2

    Re: «Remove Duplicates» not working despite «Conditional Formatting» finding the dupes

    The «Remove Duplicates» feature only removes the duplicates within the same column.

    Conditional Formatting looks at the entire selected range (which in this case is $A$1:$B$137).

    If you want to remove duplicates, you can put everything into one column, then run the remove duplicates feature.


  3. 10-21-2019, 01:44 PM


    #3

    Vitae is offline


    Registered User


    Re: «Remove Duplicates» not working despite «Conditional Formatting» finding the dupes

    Huh…I thought that it looked at both side since it shows both sides on the selector.
    The issue is that I want to keep the data in A, but remove the dupes that are in A in B.
    Like say I have

    athert:99.0 hunter:99.3
    raiderrose:99.0 shaman:99.2
    alordkirk:99.0 raiderrose:99.0
    lili:76.0 carl:99.2
    hosokawa:99.2 nimue:72.0

    I want B to be

    athert:99.0 hunter:99.3
    raiderrose:99.0 shaman:99.2
    alordkirk:99.0 carl:99.2
    lili:76.0 nimue:72.0
    hosokawa:99.2

    I’d found these directions when I searched for «excel remove specific duplicates»

    Remove duplicate values
    Select the range of cells that has duplicate values you want to remove. Tip: Remove any outlines or subtotals from your data before trying to remove duplicates.
    Click Data > Remove Duplicates, and then Under Columns, check or uncheck the columns where you want to remove the duplicates.
    Click OK.

    BUT I guess that meant to «not search those columns.» I took it to mean what I wanted it to do.


  4. 10-21-2019, 02:02 PM


    #4

    Vitae is offline


    Registered User


    Re: «Remove Duplicates» not working despite «Conditional Formatting» finding the dupes

    Ok, found another post via Google with an inelegant work around that pretty much says the same as the suggestion 63falcondude gave.
    Take the data from B, post it directly below A and do the remove Duplicates.
    Then just take from where A was supposed to end and Cut/Paste back to B. Remove Dupes works sequentially so it won’t toss something higher up 1st.
    Like I said, inelegant. But at least I can work that into a Macro and have it do it that way.
    This sure wouldn’t work with more than 2 Columns.
    Kinda pointless of Remove Dupes to not work across all highlighted Rows/Columns.

    Last edited by Vitae; 10-21-2019 at 02:05 PM.


  5. 10-21-2019, 02:13 PM


    #5

    Re: «Remove Duplicates» not working despite «Conditional Formatting» finding the dupes

    If you are okay with a VBA solution (I can’t help here), I’m sure there is one that can remove duplicates in an unstructured range like you have here without putting everything into one column.

    The remove duplicates feature does work across multiple rows/columns but not how you are thinking.
    It is built to remove duplicate lines of data in a structured data layout (1 header row, then each row of data beneath it containing multiple «linked» columns).

    Having your data structured like this (where adjacent columns of each row belong together) will make it easier to work with Excel.


  6. 10-21-2019, 02:16 PM


    #6

    Re: «Remove Duplicates» not working despite «Conditional Formatting» finding the dupes

    If you want to do it by formula, rather than manually copy/pasting etc., you can first of all insert a new blank row at the top of your file, so that your data now starts on row 2, then you can use these formulae in the cells stated:

    F2: =IF(COUNTIF(A:A,B2),»-«,MAX(F$1:F1)+1)

    G2: =IFERROR(INDEX(B:B,MATCH(ROWS($1:1),F:F,0)),»»)

    Copy both formulae down to the bottom of your data. You can fix the values in column G, then delete the other columns (easy to include in a macro).

    Hope this helps.

    Pete


  7. 10-21-2019, 03:11 PM


    #7

    Vitae is offline


    Registered User


    Re: «Remove Duplicates» not working despite «Conditional Formatting» finding the dupes

    Wrote up a quick Macro

    What’s this doing:
    It’s going to the 1st cell of your duplicates (In my case N2 and assuming of course that the ones you want to delete are on the right side). Selecting and cutting them.
    Then, again, assuming that you have some extra data in L, it’s going to the bottom of it, moving 1 more down and to the right and pasting in the previously cut data.
    Performing the Remove Duplicates function.
    Again, moving to L and 1 down/right
    Selecting and cutting from there to the end and pasting it back into the 1st cell of the column that shouldn’t have any dupes.

    The reasoning for the L column is cause I have a «Top 60 Heroes» list and the #’s 1 thru 60 in L. So, basically it goes to L and then like I said, goes down then 1 more down and then takes a left to the open cell.
    You could alter this if you don’t have any data in the left most cell by changing the 1st one to
    Cells(Rows.Count, «L»).End(xlUp).Offset(1, 0).Select
    That will just go down and down 1 more to the open cell.
    And then replace the 2nd one with
    Range(«M62»).Select
    Where M62 is the 1st cell after the ones you wanted to keep.
    I have a header on M1 so that’s the reason for the 62 and not 61. And for some reason, my mind, when I see that I’m on row 61, immediately thinks that I have 61 heroes listed even tho I KNOW I only have 60. SO, I did the #’s to keep me centered.

    I’m sure I’ve kinda explained this badly because what goes on in my head doesn’t always translate to my fingers

    Last edited by Vitae; 10-21-2019 at 03:20 PM.


  8. 10-21-2019, 03:34 PM


    #8

    Re: «Remove Duplicates» not working despite «Conditional Formatting» finding the dupes

    I’m glad that you found a solution that works for you.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.


You cannot remove duplicates in Power BI’s data model — you can filter, but not remove.

In Power Query, you can, There are two ways to do it. Right-click on a column and that will remove duplicates from that column regardless of what is in the other columns. Or, in the grid view, click the little table icon in the upper left corner to get the menu. Near the bottom is Remove Duplicates — this will only remove rows that are duplicates — every value in a column is checked.

Note though that this will NOT remove all nulls, which will cause a problem if you are trying to create a DIM table with a 1 to Many relationship. DIM tables cannot have nulls in their primary key, so usually I do both — remove duplicates on the primary key, then remove empty.

If that isn’t what you need, please give us more info. We cannot see your dataset nor do we understand your data.

Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling

Proud to be a Super User!

MCSA: BI Reporting

RemoveDuplicates in VBA Excel

Duplicate values are often not required in Excel, especially when you want to have unique values count. It is because we usually have a different set of data to work with, and we see a bunch of duplicate values in it.

We hope you are familiar with removing duplicates in excelTo remove duplicates from the excel column, the user can adopt any of the three well-known methods: Using data tools group, Using the advanced filter in excel, Conditional formatting in excel.read more worksheets. If not, there is nothing to worry about. We will show you a simple example for you. In VBA, too, we can perform the remove duplicates method.

So, It has removed all the duplicate values of the “Region” heading. Similarly, we can do this task with the help of the VBA codeVBA code refers to a set of instructions written by the user in the Visual Basic Applications programming language on a Visual Basic Editor (VBE) to perform a specific task.read more.

Table of contents
  • RemoveDuplicates in VBA Excel
    • How to Remove Duplicate Values in VBA Coding?
    • Examples of Remove Duplicate Values in VBA Coding
      • VBA Remove duplicates – Example #1
      • VBA Remove duplicates – Example #2
      • VBA Remove Duplicates from Multiple Columns – Example #3
    • Recommended Articles

VBA Remove Duplicates

You are free to use this image on you website, templates, etc., Please provide us with an attribution linkArticle Link to be Hyperlinked
For eg:
Source: VBA Remove Duplicates (wallstreetmojo.com)

How to Remove Duplicate Values in VBA Coding?

To remove duplicate values, first, we need to mention the range we are referring to. Then we can access the “Remove Duplicates” method. So syntax will be as follows.

VBA Remove 1

[Column]: Which selection column do we need to remove duplicates? We need to mention the column number of the selected range.

[Header]: The range you have selected has either headers or not. So, we have three options to work with here.

  • xlYes: If the data has headers, then you can select this.
  • xlNo: If the data doesn’t have headers, you can select this.
  • xlGuess: This option will allow Excel to guess the data headers.

So, using these parameters, we can remove duplicates with just a click of a button without breaking our sweat.

In the below section, we will show examples to VBAHere’s a list of the top examples of VBA Macro code in Excel: Print All Sheet Names, Insert Different Color Index in VBA, Insert Worksheets as Much as You want, Insert Blank Row After Every Other Row
Highlight Spelling Mistakes.
read more
removing duplicates. Follow the steps carefully to write the code on your own.

Examples of Remove Duplicate Values in VBA Coding

Below are the examples of RemoveDuplicate in Values VBA.

VBA Remove duplicates – Example #1

Consider the below data for this example as well.

Remove Duplicate Example 1

We need to remove “Region” column duplicates from the above data, so follow the steps below to write the code.

Step 1: Start the sub procedure by giving a Macro code name.

Step 2: Mention the range of data by using the VBA Range object.

Code:

Sub Remove_Duplicates_Example1()

  Range ("A1:C9").

End Sub

VBA Remove Duplicate Step 1

Step 3: After mentioning the range access VBA “RemoveDuplicates” method.

Code:

Sub Remove_Duplicates_Example1()

  Range("A1:C9").RemoveDuplicates

End Sub

VBA Remove Duplicate Step 2

Step 4: First argument in which column we need to remove the duplicate values. In this example, we need to remove the duplicates from the first column.

Code:

Sub Remove_Duplicates_Example1()

  Range("A1:C9").RemoveDuplicates Columns:=1,

End Sub

VBA Remove Duplicate Step 3

Step 5: Next thing is whether the data has headers or not. In this case, we have headers, so select “xlYes.”

Code:

Sub Remove_Duplicates_Example1()

  Range("A1:C9").RemoveDuplicates Columns:=1, Header:=xlYes

End Sub

VBA Remove Duplicate Step 4

Run this code. It will remove duplicates from the selected region.

VBA Remove Duplicate Step 5

It is a straightforward way of referring to the range of cells. However, if you wish to select the range on your own and remove duplicates, then we need to use the variable to work with. In the below example, we will show you how to use variables in VBA.

VBA Remove duplicates – Example #2

In the above example, we have specifically supplied the range of cells. Now, we will see how to work with selecting our cells.

For example, we have a few data sets, as shown in the image below.

VBA Remove Duplicate Example 2

We cannot explicitly specify the range of cells so we will assign the selection as the range.

Step 1: Declare the variable as Range.

Code:

Sub Remove_Duplicates_Example2()

  Dim Rng As Range

End Sub

VBA Remove Duplicate Example 2-1

Step 2: Range is an object. We will set the range as our selection.

Code:

Sub Remove_Duplicates_Example2()

  Dim Rng As Range
  
  Set Rng = Selection

End Sub

Example 2-2

Step 3: Instead of a range of cells, we can use the variable “rng.”

Code:

Sub Remove_Duplicates_Example2()

  Dim Rng As Range

  Set Rng = Selection

  Rng.RemoveDuplicates Columns:=1, Header:=xlYes

End Sub

Example 2-3

Before running the code, we must select the range of cells first. Then, we can remove duplicates from the selected range of cells.

Example 2-4

VBA Remove Duplicates from Multiple Columns – Example #3

We can also use VBA to remove duplicate values from excel columnsTo remove duplicates from the excel column, the user can adopt any of the three well-known methods: Using data tools group, Using the advanced filter in excel, Conditional formatting in excel.read more. Finally, we need to use an array to remove multiple columns and mention the column numbers.

For example, look at the example data image.

Remove Multiple Columns Example 3

We have duplicate values in the first column and fourth column. So, we will remove these columns. Use the below code to VBA to remove duplicates.

Code:

Sub Remove_Duplicates_Example3()

  Dim Rng As Range
  Set Rng = Range("A1:D9")

  Rng.RemoveDuplicates Columns:=Array(1, 4), Header:=xlYes

End Sub

You can download this VBA Remove Duplicates Excel here. VBA Remove Duplicates Excel Template

Recommended Articles

This article has been a guide to VBA Remove Duplicates. Here, we learn how to remove duplicate values in Excel VBA, examples and download an Excel template. Below are some useful Excel articles related to VBA: –

  • VBA LikeVBA Like is a comparison operator that matches a pattern by comparing a given string as an argument in a set of strings.read more
  • VBA Pivot TablePivot Tables are at the heart of summarizing a large amount of data.  We can also use VBA coding to automate the process of creating a pivot table.read more
  • Find Duplicates in ExcelIn MS Excel, the duplicate values can be found and removed from a data set. Depending on your data and requirement, the most commonly used methods are the conditional formatting feature or the COUNTIF formula to find and highlight the duplicates for a specific number of occurrences. The columns of the data set can be then filtered to view the duplicate values.
    read more
  • Highlight Duplicates in ExcelHighlight Cells Rule, which is available under Conditional Formatting under the Home menu tab, can be used to highlight duplicate values in the selected dataset, whether it is a column or row of a table.read more

0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии

А вот еще интересные материалы:

  • Яшка сломя голову остановился исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного где ошибка
  • You can swim где ошибка
  • You can see the only real source ошибка