+ Reply to Thread
Results 1 to 6 of 6

Loop Through Column Headings and Delete Columns

  1. #1
    Forum Contributor
    Join Date
    11-01-2012
    Location
    NJ
    MS-Off Ver
    Excel 365
    Posts
    109

    Loop Through Column Headings and Delete Columns

    Hello,

    I have a bunch of different files that are all uniquely named with each of the column headings in 30 Columns starting in Column C.

    I am trying to loop through row 1 where the column headings are and delete the columns that do not match the file name. Then move to the next file.

    Below is what I have but I am a novice and can't get it work.

    Any help would be appreciated!

    Thanks

    Please Login or Register  to view this content.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,877

    Re: Loop Through Column Headings and Delete Columns

    What is not working here? Are you getting an error message. Perhaps load a sample file that represents an actual file.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Contributor
    Join Date
    11-01-2012
    Location
    NJ
    MS-Off Ver
    Excel 365
    Posts
    109

    Re: Loop Through Column Headings and Delete Columns

    Hi,
    Getting runtime error 424 - Object Required
    On line

    Cells(1, i).Value.EntireColumn.Delete

    Appreciate the help!

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,877

    Re: Loop Through Column Headings and Delete Columns

    Try taking out .value from the line of code so it reads
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    11-01-2012
    Location
    NJ
    MS-Off Ver
    Excel 365
    Posts
    109

    Re: Loop Through Column Headings and Delete Columns

    That's it! Thanks for that!

  6. #6
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Loop Through Column Headings and Delete Columns

    Some small additions / changes you can do.

    You have "Dim'ed" all your variables except i so you could add
    Please Login or Register  to view this content.
    and you could change

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    Alf

+ 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] Formula to Sum Multiple Columns Based on Column Headings and Other Criteria
    By webfeet2 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-10-2015, 12:20 PM
  2. [SOLVED] Delete Multiple Columns with specific column headings using a Macro.
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-30-2013, 07:28 PM
  3. [SOLVED] Sum columns based on column headings
    By Jario in forum Excel General
    Replies: 6
    Last Post: 06-29-2012, 10:37 AM
  4. Sum several columns based on column headings.
    By Jario in forum Excel General
    Replies: 2
    Last Post: 06-27-2012, 11:51 AM
  5. Transposing one column data to different columns based on their headings
    By bipindurgapal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-20-2012, 06:35 AM
  6. Compare Column Headings and Delete Nonmatch
    By bthurman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-02-2009, 01:40 PM
  7. delete specific columns by reading headings
    By sa02000 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-01-2008, 06:52 AM

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