Closed Thread
Results 1 to 8 of 8

VBA to Delete Specific Columns 100s Files for .csv

  1. #1
    Forum Contributor
    Join Date
    07-28-2009
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    99

    VBA to Delete Specific Columns 100s Files for .csv

    I am looking for a VBA program that deletes the specific columns of hundreds of CSV files in a directory. So the first row contains the headers. In the table below the columns "You" and "Too" should be removed completely from the csv file.

    While I know this can be done slowly by opening a file and then selecting the columns then deleting it takes a long time. I need a way to automate this so that I can have the column deleted completely based on the column header name.

    Also, all the csv files do not have same column header names, but there should be a rule where if the column header is supposed to be deleted but doesn't exist in the csv file then move to next header to delete.

    The csvs are pretty big too sometimes up to 500mb. So I rather not have to open each one to delete the column by running the macro. If the vba could run through entire directory and delete the specific columns that would be great.

    Ex
    Why You Bad Too Yes
    data daea 32
    3ad
    Last edited by Tommy1005; 12-12-2013 at 08:04 PM.

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: VBA to Delete Specific Columns 100s Files for .csv

    Try the attached.
    Attached Files Attached Files

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,465

    Re: VBA to Delete Specific Columns 100s Files for .csv

    Cross post and solved
    http://www.ozgrid.com/forum/showthre...063#post695063

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

    Re: VBA to Delete Specific Columns 100s Files for .csv

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).
    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

  5. #5
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: VBA to Delete Specific Columns 100s Files for .csv

    It seems like a different request though similar, that was to delete rows and this for columns.

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,465

    Re: VBA to Delete Specific Columns 100s Files for .csv

    Exactly the same.

    OP deleted the list what was the same as post #1 and the code there is deleting the column(s), not row(s).

  7. #7
    Registered User
    Join Date
    06-11-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    7

    Re: VBA to Delete Specific Columns 100s Files for .csv

    Hello,

    Sorry to revive this old thread but I'm having issues getting this code to work for my needs. I started with the above attached "EF975086 code.xlsm‎ " file and I'm trying to modify it. I'd like to delete the entire row if the text value matches what I have specified. I'm working with multiple csv files (batch) and all of the data is in column A. I've been able to get the macro to run but it does not delete the rows of data that I am trying to remove. Rather, there are no changes made.

    I need to delete the row that contains the following strings.

    Date/Time, Time stamp, Cycles of Channel 1, Channel 1-Displacement, Channel 1-Load, Channel 1-Dyn Load, Channel 1-Accel

    s, s, cycles, mm, N, N, G

    I very much appreciate your time on this matter.

    Here is my edited code:

    Please Login or Register  to view this content.

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

    Re: VBA to Delete Specific Columns 100s Files for .csv

    @brundag5

    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Delete empty cells from Columns
    By MKZS in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-06-2013, 07:57 AM
  2. Delete row if multiple columns empty
    By amadman114 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-22-2013, 06:53 AM
  3. [SOLVED] Delete rows when two columns are empty
    By Musoguy in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-29-2013, 09:00 AM
  4. how to delete empty rows or columns only
    By tallercheetah in forum Excel General
    Replies: 3
    Last Post: 02-02-2012, 10:44 AM
  5. [SOLVED] Macro to Delete empty columns
    By Darth Cor in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-02-2005, 10:05 AM

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