![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Apr 2002
Location: Decatur IL, USA
Posts: 494
|
We receive a large sheet from an outside source. It has 157 columns (A - FA), and 4041 rows.
The vendor name is in column C and the vendor address is in column D. I need a macro that will find duplicates and delete the entire row. Example: Col. C...Wonder Widgets...Col. D...123 Main Col. C...Wonder Widgets...Col. D...456 Elm Col. C...Wonder Widgets...Col. D...123 Main I want to delete only the second occurance of Wonder Widgets at 123 Main. The other two Wonder Widgets should remain in the sheet. Thanks in advance for any help, Shirlene |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Feb 2002
Location: Southfield,MI USA
Posts: 1,030
|
G'day,
The Advanced Filter feature has a way to copy "unique records only" - this is a good method if you don't need a macro. Hope that helps, Adam |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Apr 2002
Location: Decatur IL, USA
Posts: 494
|
I have tried the AutoFilter unique records feature but it won't work for these sheets. The problem is that the vendor who sends us the sheet has numbered each record with duplicate records having different numbers.
Any other suggestions? |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
Are you opposed to using a VBA macros?
If not, what is the first row your data begins on? Tom [ This Message was edited by: TsTom on 2002-04-23 04:41 ] |
|
|
|
|
|
#5 | |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
Hi again.
If you need help with this please repost. Assumes data starts on row 2... Quote:
Tom [ This Message was edited by: TsTom on 2002-04-23 05:09 ] |
|
|
|
|
|
|
#6 |
|
Board Regular
Join Date: Apr 2002
Location: Decatur IL, USA
Posts: 494
|
The macro works great on sheets that are a few hundred rows. However, it dies while working in sheets of a few thousand rows. I ran it for 20 minutes on my sheet with 4041 rows and finally found that Excel stopped responding. Any ideas?
|
|
|
|
|
|
#7 |
|
Board Regular
Join Date: Feb 2002
Location: Southfield,MI USA
Posts: 1,030
|
Hi again,
I guess you could always go with a semi-manual method (a few steps but not too horrible): 1: insert a new column somewhere and on the 2nd row use the formula =C2&D2 (copy down). The idea is to catch the criteria for a unique record - you may wish to add more cells to the concatenated to ensure a good criteria. For the example's sake I'll assume you type this formula in C2. 2. Insert a 2nd new column with the formula: =countif($C$2:C2,C2) (copy down again). 3. Copy and paste these columns as values 4. Sort by this numbered column, then manually delete any entries >1 5. (optional) resort by their initial order. Hope that helps, Adam |
|
|
|
|
|
#8 | |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
Hi
Will need a sample sheet... Unless someone can find out why my code is doing what you said. I'm assuming that the deletion of the rows might be sending it into an endless loop. Maybe try this as an alternative... Quote:
Tom |
|
|
|
|
|
|
#9 | ||
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
Hi
I failed to adjust LastRow when a row was deleted. Hence, the forever loop... As an added precaution, I added this line of code: Quote:
make this line active in the code. Quote:
Tom |
||
|
|
|
|
|
#10 |
|
Join Date: Mar 2002
Posts: 15
|
A macro can be created with the macro recorder by recording the following steps (note : it has been assumed that only column D needs to be checked for duplicates on the basis that a particular address will not have more than one customer name - if this is not the case, post again) :-
- Insert a column before column D - In the inserted column, select from D1 down to the last row with data in column E - Type in the formula =IF(COUNTIF($E$1:E1,E1)>1,1,"") and press Ctrl+Enter - Go to Edit>GoTo>Special>Formula>Numbers and click OK - Go to Edit>Delete>EntireRow - Delete Column D Here's a cleaned-up version of the recorded macro :- Sub Delete_Duplicates() Application.ScreenUpdating=False Columns(4).Insert With Range([E1], [E65536].End(xlUp)).Offset(0, -1) .FormulaR1C1 = "=IF(COUNTIF(R1C5:RC[1],RC[1])>1,1,"""")" On Error Resume Next .SpecialCells(xlCellTypeFormulas, 1).EntireRow.Delete On Error GoTo 0 .EntireColumn.Delete End With End Sub [ This Message was edited by: Brabantio on 2002-04-23 19:30 ] |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|