+ Reply to Thread
Results 1 to 15 of 15

Remove duplicated rows and sort by cell color

  1. #1
    Registered User
    Join Date
    09-26-2022
    Location
    Honduras
    MS-Off Ver
    2019
    Posts
    8

    Post Remove duplicated rows and sort by cell color

    Hi all, I need to create two buttons for an excel sheet using VBA. Let me give you some context.

    Let's say I have a sheet named "database". The complete "A" column is emtpy because I need it for somethign else, nothing so relevant, the information of the database is filled from column B to column K, and of course all records are listed below that, means that the row from B1 to K1 has the titles of the columns, information starts from B2-K2, B3-K3 and so on until the final record.

    These record will keep increasing, new records will added, means the table "height" will variate a lot, but the "width" will be the same from B to K, and also, the column "K" will be empty of information BUT it will be filled with a color, I mean, a cell fill color and it will variate, yellow, brown, blue, red, pink, etc. ONLY COLUMN K WILL BE EMPTY OF INFO BUT FOR CELL FILL COLOR!

    Now what I need, please help me.

    Button 1: to eliminate rows with duplicated index in column B, it will cycle from start of the table to the end of the table/records removing the duplicated records withing the B column
    Button 2: It will sort all the table using as it's reference the colors in the column K, I don't mind the order of the colors, it can be by the order how they are shown in the database, what I need is to all the blue records be together, also pink, red and all.

    Please I'll appreciate your help.
    Last edited by martincast; 09-27-2022 at 10:44 AM.

  2. #2
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Help please with excel VBA code

    Pls attach a sample worksheet.
    Quang PT

  3. #3
    Registered User
    Join Date
    09-26-2022
    Location
    Honduras
    MS-Off Ver
    2019
    Posts
    8

    Re: Help please with excel VBA code

    I cant post link idk why, how can i post files?

  4. #4
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Help please with excel VBA code

    see big yellow banner - explains how to
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

  5. #5
    Registered User
    Join Date
    09-26-2022
    Location
    Honduras
    MS-Off Ver
    2019
    Posts
    8

    Re: Help please with excel VBA code

    I think I uploaded it correctly
    Last edited by martincast; 09-27-2022 at 10:51 AM.

  6. #6
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Help please with excel VBA code

    Please take a minute to update your thread title based on our Forum Rules.
    HTH
    Regards, Jeff

  7. #7
    Registered User
    Join Date
    09-26-2022
    Location
    Honduras
    MS-Off Ver
    2019
    Posts
    8

    Re: Remove duplicated rows and sort by cell color

    I think I updated it correctly

  8. #8
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Remove duplicated rows and sort by cell color

    opening the VBA in your file there appear to be two lots of code relevant to a Mac, what system are you using, please make this obvious in your profile.

  9. #9
    Registered User
    Join Date
    09-26-2022
    Location
    Honduras
    MS-Off Ver
    2019
    Posts
    8

    Re: Remove duplicated rows and sort by cell color

    Sorry for all the mess, it was windows 10 but i deleted the file, not sure what code was it but i must check again if there is no confidential information, sorry for the mess

  10. #10
    Registered User
    Join Date
    09-26-2022
    Location
    Honduras
    MS-Off Ver
    2019
    Posts
    8

    Re: Remove duplicated rows and sort by cell color

    here is now the sample without any confidental info, thanks and sorry for bothering
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi, try this ...


    According to your attachment for your Button 1 an Excel basics VBA demonstration
    like any Excel beginner operating manually and using the Macro Recorder :

    PHP Code: 
    Sub Macro1()
        [
    A1].CurrentRegion.RemoveDuplicates 21
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon ? Add Reputation ? !

  12. #12
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb And this !


    According to the attachment a VBA demonstration for the Button 2 :

    PHP Code: 
    Sub Macro2()
            
    Dim R&, C&, oCol As New Collection
        With ActiveSheet
    .AutoFilter.Sort
           
    .SortFields.Clear
            On Error Resume Next
        
    For 2 To .Rng.Rows.Count
            C 
    = .Rng(R1).Interior.Color
            Err
    .Clear
            oCol
    .Add CStr(C)
            If 
    Not Err.Number Then .SortFields.Add(.Rng(1), 11, , 0).SortOnValue.Color C
        Next
            On Error 
    GoTo 0
            Set oCol 
    Nothing
           
    .Header 1
           
    .Apply
           
    .SortFields.Clear
        End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon ? Add Reputation ? !

  13. #13
    Registered User
    Join Date
    09-26-2022
    Location
    Honduras
    MS-Off Ver
    2019
    Posts
    8

    Re: Remove duplicated rows and sort by cell color

    Thank you very mcuh all let me try it!

  14. #14
    Registered User
    Join Date
    09-26-2022
    Location
    Honduras
    MS-Off Ver
    2019
    Posts
    8

    Re: Remove duplicated rows and sort by cell color

    Thank you it work just needed some modifications but works!

  15. #15
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Remove duplicated rows and sort by cell color


    As I wrote : " according to the attachment " ...

    Thanks for the rep' !

+ 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. VB Code in Outlook VB code to delete excel files from certain folder
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2018, 02:47 PM
  2. [SOLVED] Excel VB code. Message pops up while code running asking question. Code must not wait.
    By Heinrich Venter in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-28-2014, 06:10 AM
  3. [SOLVED] Excel Macro Visual Basic code not looking at all sheets with second section of code.
    By Heinrich Venter in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-10-2014, 08:26 AM
  4. Replies: 1
    Last Post: 11-13-2013, 10:28 AM
  5. Adding Text to another cell VB code (Help Tweeking code) (Excel 2007)
    By Excelnoub in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-06-2012, 11:37 AM
  6. Code for email alerts from excel isn't working, wrong code possibly?
    By jessthorogood in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-27-2012, 01:45 AM
  7. Importing Excel Macros Code from another Excel sheet which has Macro code.
    By arun.pillai in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-14-2010, 05:38 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