+ Reply to Thread
Results 1 to 10 of 10

Merge columns if certain number of columns in row

  1. #1
    Registered User
    Join Date
    07-07-2011
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    6

    Merge columns if certain number of columns in row

    I have to deal with data exported in comma delimited ascii format. When the software exports, it sends commas in with numbers. This creates a scenario where a row might have 1 number cell if the number is less than 1,000 and two number cells if the number is 1,000 or greater. For example, the number 25 would be contained in one cell while the number 5250 would be split across two cells. One with 5 and one with 250. Is there a reasonable way to create an if statement to merge cells in a row based on the total number of cells with data on that row? For example, if the row has 3 cells with data nothing would happen. But if the row has 4, it would automatically merge the numbers on that row in cell B and C. If it had 5 cells on that row, it would automatically merge cells B C and D.


    Thank you so much for your help!

  2. #2
    Registered User
    Join Date
    06-19-2012
    Location
    N/A
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: Merge columns if certain number of columns in row

    Based on your description, I'm assuming you're importing values into Column A and longer numbers are falling into Columns B & C. If that's not correct, the references in this formula will need to be adjusted:

    Please Login or Register  to view this content.
    Hope this helps.

    Edit: Also assuming you wanted to retain the commas. If not:

    Please Login or Register  to view this content.
    Last edited by rob.barnes01; 06-22-2012 at 01:13 PM.
    If I have helped, please click the star below.

  3. #3
    Registered User
    Join Date
    07-07-2011
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Merge columns if certain number of columns in row

    Wow thank you that was quick and I think I understand the logic. Can you tell me where I put that formula? I'm not really sure where it goes.

  4. #4
    Registered User
    Join Date
    06-19-2012
    Location
    N/A
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: Merge columns if certain number of columns in row

    You will place this formula wherever you want your corrected values to appear. It will correct the separation errors, but it will not replace them. Hope that make sense.

  5. #5
    Registered User
    Join Date
    07-07-2011
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Merge columns if certain number of columns in row

    Ok got it thank you I figured out how to use it with your instructions. I don't know if that will fix my particular problem though, because the data also returns another number after the number in question.

    Here is an example layout that the program returns

    A1 A2 A3 A4 A5 A6 A7
    Bobs Oil Company 985 0.02
    Bills Wind Company 2 999 0.06
    Tims Gas Company 105 200 0.10
    Rogers Nuclear 222 222 222 0.25

    The first spot is a company name. The next "group" is the dollar amount of sales per given unit of time. For bobs oil it was 985, for bills wind it was 2,999, for tims gas it was 105,200 and so on. And the last number is the percentage of total sales that company comprises. Using the formula you provided I think I would end up appending the percentage of total sales to the dollar amount figure.

    I hope I have explained this well. Any ideas? Or maybe I just don't understand something.

  6. #6
    Registered User
    Join Date
    06-19-2012
    Location
    N/A
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: Merge columns if certain number of columns in row

    OK, it looks like your values are in columns B-D. This formula should account for the percentages on the end:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-07-2011
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Merge columns if certain number of columns in row

    Wow that works great thank you very much. I only have one problem left. The resulting number that this code generates doesn't seem to be a number. I can't change its format to currency (doesn't do anything) and I can't create charts with it either. If I do a sum of these numbers it outputs only a " - " and nothing else.

    Any idea how I can change this?

  8. #8
    Registered User
    Join Date
    06-19-2012
    Location
    N/A
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: Merge columns if certain number of columns in row

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    07-07-2011
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Merge columns if certain number of columns in row

    Wow rob, that was excellent. It works perfectly. You just saved me a lot of time. I really appreciate your help, and now that I know the formula I can modify it for all of the similar reports we have. Kudos and thanks to you.

  10. #10
    Registered User
    Join Date
    06-19-2012
    Location
    N/A
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: Merge columns if certain number of columns in row

    You're very welcome. Glad I could help you out!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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