+ Reply to Thread
Results 1 to 2 of 2

Looping issue for csv clean-up macro

  1. #1
    Registered User
    Join Date
    08-10-2012
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    78

    Looping issue for csv clean-up macro

    Hi All-

    I toiled with getting a macro together to handle an issue I have with line breaks occurring in the middle of a "comments" field in the several csv files I am emailed every week. Often when the data is exported by various users, these breaks cause the fields to be misaligned.

    The code I have works perfectly if I have my cursor on col A of an affected row (in each variation of the problem), but I am having a hard time getting it to loop through line by line. When I run the full macro as is, it winds up deleting much more than intended.

    Here are the facts:

    The break always occurs in column P, resulting in data that should be in columns Q-AQ winds up in the next row, column A or half of the comment winds up in column P below. Because the comments are always split in half, I wrote code to concatenate the data before correcting it with the following steps:

    1.First it needs to delete all completely blank rows
    2.There are only 9 correct entries for column A. As long as the row begins with one of these, it should be left alone. ("HQ (Crew)", "EVANN", "EWRTH", "ERYE", "EEAST", "CWBIB", "CWPER", "CXPER", "CXWJL")
    3.Then apply the fix I have worked out when a line break occurs (shifting, concatenating, moving 2-3 rows of data into one)
    4.Finally I want it to return a message box letting the user know if any cleaning was necessary (which I accomplish by comparing the number of rows at the beginning of the macro and at the end.

    Attached is a shortened sample version of the a problem file. Below is the code I am using.

    I have it pretty thoroughly commented regarding what needs to happen when and where the issues are occuring.

    I really would sincerely appreciate any guidance you might have.

    Thanks,
    J

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Looping issue for csv clean-up macro

    Your code uses Activecell a lot, but you are not selecting the cell of interest first. Just add a line after your looping start line to set the activecell properly - that should fix a lot. Can't say anything about the rest of your logic, but you should be able to sort it out from there.

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

+ 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] Looping vlookup,If,clean cell contens VSA
    By Rocky2013 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-11-2013, 09:44 PM
  2. Looping issue
    By wani in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-30-2012, 02:23 AM
  3. Looping Macro Issue - Infinate Loops
    By frodo987 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-03-2012, 03:39 AM
  4. [SOLVED] VBA Code to optimize and clean data- clean out numerical/ or symbol
    By tracylsr in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-05-2012, 04:21 PM
  5. Need help with looping issue
    By SDBoca in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-08-2011, 08:18 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