+ Reply to Thread
Results 1 to 4 of 4

Processing CSV Files in Excel VBA

  1. #1
    Registered User
    Join Date
    12-24-2015
    Location
    Melbourne, Australia
    MS-Off Ver
    2013
    Posts
    7

    Processing CSV Files in Excel VBA

    Folks
    I receive a CSV that has 15 columns and up to 10,000 rows. Due to the potential size of the data, in my VBA, I want to process row by row as not every row is required. I created some code that reads a row of the file and uses the SPLIT command to break the data into the various columns. The problem is, one of the columns is a string that occasionally has a comma in it. When the string has a comma, the SPLIT command then breaks the string into 2 different fields and changes the location of where I expect data to be.

    Can someone please point me in the right direction on the easiest way to code around this?
    Thanks,
    Michael

  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,872

    Re: Processing CSV Files in Excel VBA

    Post your code so that it can be analyzed. Remember to use code tags as noted in the forum rules you agreed to.
    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
    Registered User
    Join Date
    12-24-2015
    Location
    Melbourne, Australia
    MS-Off Ver
    2013
    Posts
    7

    Re: Processing CSV Files in Excel VBA

    Sure Alan. I have also attached the data file I am testing with. As you can see when you run the code, the headings match what is expected. Rows 2 and 3 are offset so date for instance is no longer a date and then the remaining rows align correctly. The problem is due to the comma after "Decision" on 2 of the rows.

    Please Login or Register  to view this content.
    [data]
    Approver Id,Emp ID,Project Name,Task Name,SubTask Name,Start Time,End Time,Date,Location,Status,Group Name,Client Name,Department,Time (hrs),Prorata Time
    ,[email protected],Dummy for Tool Development - Zero,Business Analysis,"""Decision, Analysis and Resolution (DAR) preparation""",0,0,4-Jan-16,N/A,Not Approved,AUS,Program Name,1,5,5
    ,[email protected],Dummy for Tool Development - Zero,Business Analysis,"""Decision, Analysis and Resolution (DAR) preparation""",0,0,5-Jan-16,N/A,Not Approved,AUS,Program Name,1,6,6
    ,[email protected],Dummy for Tool Development - Zero,Project Management,Finance,0,0,11-Jan-16,N/A,Not Approved,AUS,Program Name,1,3,3
    ,[email protected],Dummy for Tool Development - Zero,Project Management,Finance,0,0,13-Jan-16,N/A,Not Approved,AUS,Program Name,1,5,5
    [/data]

  4. #4
    Registered User
    Join Date
    12-24-2015
    Location
    Melbourne, Australia
    MS-Off Ver
    2013
    Posts
    7

    Re: Processing CSV Files in Excel VBA

    Finally, I have an answer to this problem. By using a Regular Expression, you can replace the separators. Hopefully this helps out someone else.
    Please Login or Register  to view this content.

+ 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. excel string processing
    By kxtg2431 in forum Excel General
    Replies: 2
    Last Post: 02-23-2015, 06:21 AM
  2. [SOLVED] VBA not cycling through and processing all files in folder
    By DaveBre in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-07-2014, 05:56 AM
  3. Sheet-related processing causes Excel VBA Userform to stop processing Tab/Enter
    By Joaquin M Lopez Muno in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-22-2014, 03:02 PM
  4. Reduce processing time for processing multiple excel sheets
    By rexer231 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-06-2014, 09:25 AM
  5. Processing Multiple Files
    By asheshrocky in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-13-2011, 04:48 AM
  6. Processing xls files sequentially
    By Bjornago in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-19-2009, 06:25 PM
  7. cant select array of csv files for processing
    By lawrencef in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-08-2009, 07:41 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