+ Reply to Thread
Results 1 to 7 of 7

Concatenate formula for variable columns

  1. #1
    Registered User
    Join Date
    08-08-2014
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010-2013
    Posts
    31

    Concatenate formula for variable columns

    Good afternoon all,

    Still new to VBA and I was looking for some assistance. I have a large file I pull from SAP and bring in as a text file (150,000+ lines). The file can only be brought in using tab delimited.

    My issue is there are two columns however that have their contents split up (column headers 'reference' and 'text'). Reference, the first of the two always begins at array 16 when pulling in the file delimited and the column headers are always located in row 9. Sometimes the contents of reference split up into 5 separate columns, 3 separate columns, etc. Text, the second of the two columns always follows the last column of what Reference has been split up into.

    What I need to do is find the unknown column that text is located in the header row, insert a column and concatenate all cells to the left of the new column until I hit the static column Reference begins (16 or column P). Trouble is I don't know how many extra columns separate the reference column from the text column and it changes from week to week usually.

    Please Login or Register  to view this content.
    FormulaR1C1 does not do the trick because the number of columns change from week to week

    Thanks!

  2. #2
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Concatenate formula for variable columns

    Can you post sample data to work out a solution.
    Happy Computing ,

    Xlbiznes.

    To show your appreciation please click *

  3. #3
    Registered User
    Join Date
    08-08-2014
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010-2013
    Posts
    31

    Re: Concatenate formula for variable columns

    Here is a very condensed down version of the file and as the format appears when I finish the delimited pull in from the .txt file I export from SAP. I tried to show how the text in the 'reference' column gets broken up and there is no exact science on how many columns down the remaining text gets sent. The number of columns will also change week to week usually - so my issue is I either don't reference enough columns in my concatenate or & formula -- or too many carrying it over into the 'text' column and screwing up that data.
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Concatenate formula for variable columns

    Hi,

    try this vba solution.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    08-08-2014
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010-2013
    Posts
    31

    Re: Concatenate formula for variable columns

    That worked perfectly and for 147,000+ lines too! Last question, how would I then delete the unnecessary columns (lcol to where 'text column' begins and once again to delete the unnecessary columns from 'text column' to its end) that I no longer will need? I would think a if formula looking for a column heading would work in this instance?
    Last edited by davidktilley; 11-05-2014 at 06:59 PM.

  6. #6
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Concatenate formula for variable columns

    Here you go.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    08-08-2014
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010-2013
    Posts
    31

    Re: Concatenate formula for variable columns

    Never mind I think I figured it out

    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. [SOLVED] Macro to concatenate variable amount of columns
    By phil3061 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-15-2013, 02:53 PM
  2. Paste formula every other row, across variable number of columns
    By dchan556 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-04-2013, 12:17 PM
  3. Using A Variable In Concatenate Formula
    By DonG in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-06-2011, 10:13 PM
  4. using the value of a macro variable in a concatenate formula
    By Simon W in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-02-2006, 07:20 AM
  5. Help with a formula for concatenate and search/find with 3 columns
    By Mel in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-07-2005, 06:06 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