+ Reply to Thread
Results 1 to 16 of 16

Macro to delete Duplicate headings on Workbooks in a folder

  1. #1
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,725

    Macro to delete Duplicate headings on Workbooks in a folder

    I have tried to write code to delete duplicate headings for all workbooks in a folder that is selected

    I get a run time error when running the macro


    It would be appreciated if someone could assist me

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Macro to delete Duplicate headings on Workbooks in a folder

    Try putting this line
    Please Login or Register  to view this content.
    back to what it was originally.
    If that doesn't work, then you might want to consider giving us some more information.

  3. #3
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Macro to delete Duplicate headings on Workbooks in a folder

    Please Login or Register  to view this content.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  4. #4
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,725

    Re: Macro to delete Duplicate headings on Workbooks in a folder

    Hi Guys


    Thanks for the help, but I get a run time error


    Attached please find sample workbook, containing two duplicate headings In row1

    I have the workbooks in one folder C:\testdata


    I would like the macro to delete all duplicate headings in sheet1 in the folder


    Kindly test & amend code

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Macro to delete Duplicate headings on Workbooks in a folder

    What is the error & what line is highlighted?

  6. #6
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,725

    Re: Macro to delete Duplicate headings on Workbooks in a folder

    The error is "method of union of object_global failed"

    The following code in the line below from from Else: is highlighted



    Please Login or Register  to view this content.

  7. #7
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Macro to delete Duplicate headings on Workbooks in a folder

    That's because you have moved this line
    Please Login or Register  to view this content.
    try putting it back where it was.

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Macro to delete Duplicate headings on Workbooks in a folder

    Blank Headers there are...Try this you can...
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,725

    Re: Macro to delete Duplicate headings on Workbooks in a folder

    Thanks Guys

    The Code Runs perfectly using the amended code, but does not delete the duplicate header i.e. the second headers the are duplicated AP1 & AQ1

  10. #10
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Macro to delete Duplicate headings on Workbooks in a folder

    What duplicate headers where

  11. #11
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,725

    Re: Macro to delete Duplicate headings on Workbooks in a folder

    Ap1 & AQ1 are the same as N1 & O1 so AP1 & AQ1 to be deleted


    Kindly test & amend code
    Attached Files Attached Files

  12. #12
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Macro to delete Duplicate headings on Workbooks in a folder

    Try
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,725

    Re: Macro to delete Duplicate headings on Workbooks in a folder

    Many Thanks for the help Fluff13


    Your code works 100%

  14. #14
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Macro to delete Duplicate headings on Workbooks in a folder

    Of course...did not even consider to test...Delete code beyond loop...My bad...
    Glad you got it sorted...

  15. #15
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,725

    Re: Macro to delete Duplicate headings on Workbooks in a folder

    No Problem Sintek. At least it has been resolved and many thanks for your input and help, which I always value

  16. #16
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Macro to delete Duplicate headings on Workbooks in a folder

    You're welcome & thanks for the feedback

+ 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. [SOLVED] VBA to delete sheet with certain name in all workbooks in a folder
    By igormigor in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-14-2017, 11:01 AM
  2. Find and delete duplicate files if they exist in another specified folder
    By gws1971 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-21-2016, 09:51 AM
  3. VBA Code to delete the duplicate Headings
    By sabubakaralis in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-23-2014, 12:46 PM
  4. [SOLVED] VBA to copy and paste from all workbooks in folder, THEN DUPLICATE
    By Ravenous in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 04-19-2013, 02:36 AM
  5. [SOLVED] Delete A Worksheet From All Workbooks In A Folder
    By AlexRoberts in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-26-2011, 02:01 PM
  6. Delete duplicate headings
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-11-2005, 08:05 PM

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