+ Reply to Thread
Results 1 to 3 of 3

Splitting a string into cells using VBA

  1. #1
    Registered User
    Join Date
    04-20-2011
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    43

    Splitting a string into cells using VBA

    Hi All,

    I am working on some code to assist in testing and validation of a computer created CSV file. This will output one or more fixed length strings, but in order to be able to test the output easily, I need to split the string into it's component parts again, so it can be visually tested against the design template (The format is because of a legacy file scraper that will take the eventual output). The code to test this via the scraper hasn't been delivered by our third party supplier, but the data file part is completed (we think).

    The input string is made of a number of fixed length values one after the other(spaces are significant characters). Part of the list of offsets and lengths is below
    Offset 0 2 8 11 17
    Length 2 6 3 6 3

    The input strings will look something like this:
    1020306KFK1253 031100003840AC01000000007500,38CCDF98KK0707201301//33061100001
    I can do this on cell by cell basis using hundreds of variants of =MID($A2,Scratch!B$3,Scratch!B$4) and just change the values for all the cells and rows. However the matrix is 50 columns wide and the number of rows of data in the final output could be up to 10,000 rows daily.

    The Scratch workbook contains the table of Offsets and lengths

    The MID statement would return 10 as a value,
    the next one would return 20306K
    The next FK1 etc etc.

    Rather than make a rod for my own back, is there an easy way to do this in a macro or bit of code?
    Last edited by asparak; 03-10-2014 at 09:02 AM. Reason: This part of problem solved

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,616

    Re: Splitting a string into cells using VBA

    How about doing it with a code like:
    Please Login or Register  to view this content.
    and a loop for all rows.

    Or ... it seams that the string shall be splitted for consequtive pieces (no characters from input string is rejected at all) - the following code shall do
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Kaper; 03-10-2014 at 05:55 AM. Reason: added attachment
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    04-20-2011
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    43

    Re: Splitting a string into cells using VBA

    Hi Kaper,

    Thank you very much. I'll test that now. Nothing gets rejected. There is a find and replace I'll need to do at a later stage, where a '/' in a string will be replaced by a number of spaces equivalent to the offset, but that's my next thing to work out.

+ 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] Splitting a string of numbers into separate cells: where to even begin?
    By confused_teacher in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 06-03-2013, 02:33 PM
  2. splitting a string
    By spinkung in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-29-2012, 08:57 AM
  3. Replies: 6
    Last Post: 06-08-2012, 04:54 AM
  4. Splitting cells into multiple columns by specific string
    By KrNpRiDe in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-17-2009, 12:36 PM
  5. [SOLVED] Splitting a text string into string and number
    By mcambrose in forum Excel General
    Replies: 4
    Last Post: 02-21-2006, 11:50 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