+ Reply to Thread
Results 1 to 9 of 9

Concatenate question

  1. #1
    Registered User
    Join Date
    10-16-2012
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    4

    Concatenate question

    Hi,

    I have over 350 ID numbers in excel in 1 column that I need to string togeather to run a SQL query.

    i.e

    ID
    1
    34
    56
    67
    78
    23
    1233
    4567

    Which I can concatenate into '1', using =CONCATENATE("'",A2,"'",",")
    But how do I concatenate so I get '1','34','56','67' etc

    I'll be running different values in the ID column for different queries which will vary and was hoping there was a way I can add a formula so I can just then use and add data to my saved query.

    Hope this isn't too dumb a question btw

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,053

    Re: Concatenate question

    try this UDF.

    If you want ' at start use:

    ="'"&F_conc_col_noblanks_sep_snb(A1:A15,"','")
    Attached Files Attached Files
    Never use Merged Cells in Excel

  3. #3
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Concatenate question

    Ni Ninja,

    Try using below formula:-

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    See yellow cell in ttached:- concatenate for SQL.xlsx

    Regards,
    DILIPandey

    <click on below 'star' if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), dilipandey@gmail.com

  4. #4
    Registered User
    Join Date
    10-16-2012
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Concatenate question

    Hi Thanks guys!

    Zabor, I couldn't get yours to work I tried and changed the range to the data I wanted and I get #NAME
    dilipandey - your worked, but from what I can tell and trying it, it means I have to apply it to each cell?

    What I have is a sheet of data with column A which is 350 ID numbers i.e 350 lines. (and this number will grow over the coming weeks)
    I filter the ID's on type, so I may end up with 50 lines, but filtered.
    From that filtered down info, I want to concatante the ID lines into one string of data that looks something like '1','34','56','67'

    As there are so many lines I was hoping to avoid applying a formula to each line... is that possible?

    Hope that makes sense.

  5. #5
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,053

    Re: Concatenate question

    You must copy also CODE into your workbook.

  6. #6
    Registered User
    Join Date
    10-16-2012
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Concatenate question

    You've lost me - what do you mean by code? I have had no SQL training, I just use a query someone else created and run that! I copied your formula into the workbook and amended the cell range. I got an error.

    I got DILIPandey's to work

  7. #7
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,053

    Re: Concatenate question

    That's not standard formula and you must copy also code with it.
    DP formula works but it's hard enter longer ranges.
    Also, if some cell is blank then you will get something like '1''''''''10'''1'''1'

    To copy code open mine above example, press Alt+11 and from module1 copy whole code to module1 in your workbook (same procedure, insert module when you open VB editor.

  8. #8
    Registered User
    Join Date
    10-16-2012
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Concatenate question

    That works Zbor! Thankyou and that is so cool! :D

  9. #9
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Concatenate question

    @ ninjablossom

    Welcome to the forum.

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

+ 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