+ Reply to Thread
Results 1 to 13 of 13

Exception to remove duplicates function

Hybrid View

priyadharshane Exception to remove... 02-15-2019, 12:36 PM
priyadharshane Re: Exception to remove... 02-15-2019, 03:09 PM
Mumps1 Re: Exception to remove... 02-16-2019, 01:05 PM
priyadharshane Re: Exception to remove... 02-16-2019, 01:52 PM
Mumps1 Re: Exception to remove... 02-16-2019, 02:41 PM
priyadharshane Re: Exception to remove... 02-16-2019, 03:14 PM
Mumps1 Re: Exception to remove... 02-16-2019, 03:24 PM
priyadharshane Re: Exception to remove... 02-16-2019, 04:03 PM
Mumps1 Re: Exception to remove... 02-16-2019, 04:07 PM
priyadharshane Re: Exception to remove... 02-16-2019, 04:09 PM
Mumps1 Re: Exception to remove... 02-16-2019, 04:38 PM
priyadharshane Re: Exception to remove... 02-16-2019, 04:51 PM
Mumps1 Re: Exception to remove... 02-17-2019, 09:43 AM
  1. #1
    Registered User
    Join Date
    01-24-2019
    Location
    Chennai
    MS-Off Ver
    2013
    Posts
    96

    Exception to remove duplicates function

    Hello,

    I need a exception code for not deleting below content of my packing list.

    Let me be clear I wrote below function to clear all unwanted duplicated from my packing list. Unfortunately, some parts has same content as Gross weight and Net weight which below code consider as duplicates and delete it off.

    I want some code exception to surpass this content alone. Enclosed spreadsheet which has gross weight content which starts with lots of space as it's imported from a text file.

    Need your support please


    Sub DeleteRows()

    Range("A1").Select
        ActiveSheet.Range(Selection, ActiveCell.SpecialCells(xlLastCell)).RemoveDuplicates Columns:=1, Header:=xlYes
    End Sub
    Attached Files Attached Files
    Last edited by priyadharshane; 02-16-2019 at 06:04 AM.

  2. #2
    Registered User
    Join Date
    01-24-2019
    Location
    Chennai
    MS-Off Ver
    2013
    Posts
    96

    Re: Exception to remove duplicates function

    Hi,

    Can we make a condition if A column cell starts with Character 32 which is space it should not delete duplicates. I dont know how to compile in code. Can anyone support please?

    If Left(C, 1) = Chr(32)
    Last edited by priyadharshane; 02-16-2019 at 06:05 AM.

  3. #3
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,050

    Re: Exception to remove duplicates function

    Please attach a file that has more data and then explain in detail what you want to do referring to specific cells, rows and columns. It would help if you could include a sheet that contains the expected results after running the macro.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  4. #4
    Registered User
    Join Date
    01-24-2019
    Location
    Chennai
    MS-Off Ver
    2013
    Posts
    96

    Re: Exception to remove duplicates function

    Enclosed attachment as requested. I dont want rows highlighted in yellow deleted as duplicates

    I need this content. I tried to filter out and do remove duplicates but its not working
    Attached Files Attached Files

  5. #5
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,050

    Re: Exception to remove duplicates function

    Try this on a copy of your file:
    Sub DeleteDuplicates()
        Dim LastRow As Long
        LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        With Application
            ' Turn off screen updating to increase performance
            .ScreenUpdating = False
            Dim LastColumn As Integer
            LastColumn = Cells.Find(What:="*", After:=Range("A1"), SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column + 1
            With Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)
                ' Use AdvanceFilter to filter unique values
                .AdvancedFilter Action:=xlFilterInPlace, Unique:=True
                .SpecialCells(xlCellTypeVisible).Offset(0, LastColumn - 1).Value = 1
                On Error Resume Next
                ActiveSheet.ShowAllData
                Range("A1:B" & LastRow).AutoFilter Field:=1, Criteria1:=RGB(255, 255, 0), Operator:=xlFilterCellColor
                Range("B1:B" & LastRow).SpecialCells(xlCellTypeVisible) = 1
                ActiveSheet.ShowAllData
                'Delete the blank rows
                Columns(LastColumn).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
                Err.Clear
            End With
            'Columns(LastColumn).Clear
            .ScreenUpdating = True
        End With
    End Sub

  6. #6
    Registered User
    Join Date
    01-24-2019
    Location
    Chennai
    MS-Off Ver
    2013
    Posts
    96

    Re: Exception to remove duplicates function

    @ Mumps1

    I'm sorry as im not clear enough to you

    I highlighted the cell in yellow only for clarity. This is our packing list and it tends to change as dynamic

    If you closely look at highlighted cell it contains Gross weight and Net weight of the boxes shipped.

    Sometimes it has same value, when I apply remove duplicates function VBA assuming this as duplicates and deleting it which is needed. As you see all data is in Column A

    since i'm importing it from a text file. So, I dont any content in B column which will affect text to column macro which i'm applying latter part

    Prime goal of this procedure is to delete all duplicates in Column A excluding cells with gross weight in it. Excel should not consider this cell whilst deleting duplicates

    Also, there should not be any content in Column B. I tried to filter and exclude cells with gross weight in it and apply remove duplicates function. Still, It is getting deleted
    Sub DeleteRows()
    
        Dim ws As Worksheet
        Dim lRow As Long
        Dim strSearch As String
        
        Call DeleteUndefinedText
    
        
        Range("A1").Select
        
        Selection.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    
        '~~> Set this to the relevant worksheet
        Set ws = ThisWorkbook.ActiveSheet
    
        '~~> Search Text
        strSearch = "Gross Weight"
    
        With ws
            '~~> Remove any filters
            .AutoFilterMode = False
            
            lRow = .Range("A" & .Rows.Count).End(xlUp).Row
    
            With .Range("A1:A" & lRow)
            .AutoFilter Field:=1, Criteria1:="<>*" & strSearch & "*"
             .Offset(1, 0).SpecialCells(xlCellTypeVisible).Select
            End With
            
            Selection.SpecialCells(xlCellTypeVisible).RemoveDuplicates Columns:=1, Header:=xlYes
    
            
    
            '~~> Remove any filters
            .AutoFilterMode = False
        End With
        
        
        
        
    End Sub
    Attached Files Attached Files

  7. #7
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,050

    Re: Exception to remove duplicates function

    Try this version:
    Sub DeleteDuplicates()
        Dim LastRow As Long
        LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        With Application
            ' Turn off screen updating to increase performance
            .ScreenUpdating = False
            Dim LastColumn As Integer
            LastColumn = Cells.Find(What:="*", After:=Range("A1"), SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column + 1
            With Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)
                ' Use AdvanceFilter to filter unique values
                .AdvancedFilter Action:=xlFilterInPlace, Unique:=True
                .SpecialCells(xlCellTypeVisible).Offset(0, LastColumn - 1).Value = 1
                On Error Resume Next
                ActiveSheet.ShowAllData
                Range("A1:B" & LastRow).AutoFilter Field:=1, Criteria1:="=Gross Weight*"
                Range("B1:B" & LastRow).SpecialCells(xlCellTypeVisible) = 1
                ActiveSheet.ShowAllData
                'Delete the blank rows
                Columns(LastColumn).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
                Err.Clear
            End With
            Columns(LastColumn).Clear
            .ScreenUpdating = True
        End With
    End Sub
    Column B which is a helper column will be cleared.

  8. #8
    Registered User
    Join Date
    01-24-2019
    Location
    Chennai
    MS-Off Ver
    2013
    Posts
    96

    Re: Exception to remove duplicates function

    @ Mumps1 - Awesome, it's great work and helped us to automate hectic work . You are the best

    I have one more question and just let know if it's possible are not. Please let know If I need to post as different one

    I will explain you the steps I do - I run a macro - It asks me to upload packing list text file - Macro runs and add new sheet before sheet 1 naming with text file itself.

    My question - Is it possible to copy added sheet (Sheet name = Text file name) - Open a new work book - Paste the content and save workbook as Sheet name into specified location in computer

    Let says C:\Users\Desktop\Packing list as of now. I will change it later - Text file name = Macro run sheet name = Workbook name should be same. I have already done first two.

    last copied sheet must be deleted (Not sheet 1 only Macro run sheet)

    Can this be done?

    Kudos Mate!! I need to add more reputation for you

  9. #9
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,050

    Re: Exception to remove duplicates function

    Can you post the macro you run to upload packing list text file?

  10. #10
    Registered User
    Join Date
    01-24-2019
    Location
    Chennai
    MS-Off Ver
    2013
    Posts
    96

    Re: Exception to remove duplicates function

    Here you go
    Sub ImportPackinglistTextFile()
        Dim Textfile As Workbook
        Dim openfiles() As Variant
        Dim i As Integer
        
        openfiles = Application.GetOpenFilename(Title:="Select File(s) to Import", MultiSelect:=True)
        
        Application.ScreenUpdating = False
        
        
        For i = 1 To Application.CountA(openfiles)
        
            Set Textfile = Workbooks.Open(openfiles(i))
            Textfile.Sheets(1).UsedRange.Select
            Selection.Copy
            Workbooks(1).Activate
            Workbooks(1).Worksheets.Add
            ActiveSheet.Paste
            ActiveSheet.Name = Textfile.Name
            Application.CutCopyMode = False
            Textfile.Close
        Next i
        
            Application.ScreenUpdating = True
              
    End Sub

  11. #11
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,050

    Re: Exception to remove duplicates function

    Try:
    Sub ImportPackinglistTextFile()
        Dim Textfile As Workbook
        Dim openfiles() As Variant
        Dim i As Integer
        openfiles = Application.GetOpenFilename(Title:="Select File(s) to Import", MultiSelect:=True)
        Application.ScreenUpdating = False
        For i = 1 To Application.CountA(openfiles)
            Set Textfile = Workbooks.Open(openfiles(i))
            Textfile.Sheets(1).UsedRange.Copy
            Workbooks(1).Activate
            Workbooks(1).Worksheets.Add
            ActiveSheet.Paste
            ActiveSheet.Name = Textfile.Name
            ActiveSheet.Copy
            ActiveWorkbook.SaveAs Filename:="C:\Users\Desktop\Packing list\" & ActiveSheet.Name & ".xlsx", FileFormat:=51
            Textfile.Close
        Next i
        Application.ScreenUpdating = True
    End Sub

  12. #12
    Registered User
    Join Date
    01-24-2019
    Location
    Chennai
    MS-Off Ver
    2013
    Posts
    96

    Re: Exception to remove duplicates function

    @ Mumps1

    Few things, I need to copy and save macro file only after it runs. So I added this code to compiled one

    Few things causing issue,

    One - It is copying sheet 1 as well and saving it in location. I dont want to consider sheet 1 which is empty

    Two - New work books added is not closing. I want to get it saved in specific location thats it - I added code close active work book

    Three - Active sheet which is being copied is not deleting once pasted


    Sub RunPackinglist()
        MsgBox "Please upload Packinglist(s) .Txt file"
        Call ImportPackinglistTextFile
        Dim ws As Worksheet
        
        Application.ScreenUpdating = False
        For Each ws In Sheets
        ws.Activate
            If ws.Name <> "Sheet1" Then
            Call Packinglist_Compilation
            End If
            ActiveSheet.Copy
            ActiveWorkbook.SaveAs Filename:="C:\Users\elumap2\Desktop\Packing list\" & ActiveSheet.Name & ".xlsx", FileFormat:=51
        Next ws
        
        Application.ScreenUpdating = True
    
    End Sub
    Last edited by priyadharshane; 02-16-2019 at 05:20 PM.

  13. #13
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,050

    Re: Exception to remove duplicates function

    Please post the ImportPackinglistTextFile macro. You want to loop through all the sheets in the Packinglist(s) file, ignoring "Sheet1". Then you want to copy each sheet to a new workbook and save the new workbook, close the new workbook and delete the copied sheet in the Packinglist(s) file. This this correct?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Remove Duplicates Function
    By Prodetik in forum Excel General
    Replies: 2
    Last Post: 10-04-2016, 05:39 PM
  2. [SOLVED] Remove Duplicates Function for Single Cells
    By the_red_engine in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 09-17-2016, 08:20 PM
  3. Remove Duplicates Function
    By Keshypops in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-17-2015, 06:59 AM
  4. Remove duplicates function not removing duplicates
    By Berilium2 in forum Excel General
    Replies: 3
    Last Post: 04-01-2015, 06:55 AM
  5. [SOLVED] function to remove duplicates from different sheets
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-03-2014, 08:03 AM
  6. Top 40 values with duplicates and with exception
    By Fabienne88 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-02-2013, 07:57 AM
  7. How to use find/replace to remove back carriages BUT make exception to bullet points?
    By WoW_Excel_girl88 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-16-2012, 12:27 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1