+ Reply to Thread
Results 1 to 11 of 11

Add characters to number in current cell(s)

  1. #1
    Forum Contributor
    Join Date
    01-18-2010
    Location
    Bentley, NM
    MS-Off Ver
    Excel 2010
    Posts
    229

    Add characters to number in current cell(s)

    Often I need to paste lists of numbers into SQL server from Excel for an 'In' statement of a 'where' clause. In order for SQL server to recognize them they need to be formatted like this " '123456' ". Also, I will need to place a comma at the end of each number except the last one, so the where statement works. This will change the format to this " '123456', " on all but the final number. So, the code needs to work for all lists with 1 or more numbers.

    I see the process of events happening thusly:
    1. Select number at the top of the list
    2. Execute code that will:
    3. Apply formatting described above, but in a new column, so originals aren't effected
    4. Copy formatted values to clipboard
    5. Delete new column with formatted values assuming everything goes well

    I think I could use excel's record macro feature to figure a lot of this out, but it would be rather sloppy. Any help is appreciated!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Add characters to number in current cell(s)

    This will take the values from column starting in row 1, convert them as required and put the resultant list on the clipboard.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    01-18-2010
    Location
    Bentley, NM
    MS-Off Ver
    Excel 2010
    Posts
    229

    Re: Add characters to number in current cell(s)

    Using Excel 2010 and I am unable to find a reference to MS Forms. Here is what I found from MS regarding the .dll:

    The Fm20.dll is NOT redistributable. You must have an application such as Microsoft Office 97 on the target system that installs Fm20.dll as part of its setup. (Fm20.dll is included with the OSR2 and OSR2.5 releases of Windows 95.) You can also find this file on the Visual Basic 5.0 CD under the \TOOLS\DataTool\Datatool\Msdesign folder. This will be installed only if you run the setup for the Visual Database Tools. In any case, you may not distribute the Fm20.dll as part of your setup, even if you purchase the Microsoft Office Developer Edition product.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Add characters to number in current cell(s)

    The easiest way to get the reference is to add a userform.

  5. #5
    Forum Contributor
    Join Date
    01-18-2010
    Location
    Bentley, NM
    MS-Off Ver
    Excel 2010
    Posts
    229

    Re: Add characters to number in current cell(s)

    Added the reference no problem. Now I've tried to modify your code to use the ActiveCell. It works, but also includes a few blank fields. I've read that using ActiveCell could be the culprit? Here is the new code:

    Please Login or Register  to view this content.
    Also, I would like for the lists to not be transposed.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Add characters to number in current cell(s)

    Try this.
    Please Login or Register  to view this content.
    As for transposing, the array needs to be transposed for the code to work and transposing doesn't actually change anything, you'll have the same values in the same order - mind you the order doesn't matter in the SQL.

  7. #7
    Forum Contributor
    Join Date
    01-18-2010
    Location
    Bentley, NM
    MS-Off Ver
    Excel 2010
    Posts
    229

    Re: Add characters to number in current cell(s)

    Works perfect! The reason transposing is an issue is if I have a large list of numbers I will have to scroll very far to the right to see them in SQL Server vs. scrolling down to view them in a sort of list.

    Can I 'untranspose' after the fact?

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Add characters to number in current cell(s)

    I'm not sure what you mean.

    Do you want to list the values down rather than across?

    If you do then surely you'll have the same problem but in a different direction, ie you'd have to scroll down instead of across to see all the values.

    By the way, in SMSS there's an option to turn on Word Wrap, I think it's under Tools>Options>Text editor...

  9. #9
    Forum Contributor
    Join Date
    01-18-2010
    Location
    Bentley, NM
    MS-Off Ver
    Excel 2010
    Posts
    229

    Re: Add characters to number in current cell(s)

    Yes, I wanted them down vs. across. Just for ease of viewing. I'll give word wrap a try for now! Shouldn't cause any issues.

    Thanks for all your help!

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Add characters to number in current cell(s)

    Still don't quite see it myself but this would put each value on it's own row which will probably mean the main part of the SQL statement will disappear.
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    01-18-2010
    Location
    Bentley, NM
    MS-Off Ver
    Excel 2010
    Posts
    229

    Re: Add characters to number in current cell(s)

    Not having worked in SSMS for very long, listing large sets of data vertically was personally much easier to view than horizontally. With word wrap though, things are looking much better.

+ 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. New line in cell after certain number of characters, or where a number stands
    By barqujo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-08-2013, 01:14 PM
  2. number of characters in a cell
    By profector in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-12-2007, 05:36 PM
  3. How can I get current cell row number
    By excelneophyte in forum Excel General
    Replies: 1
    Last Post: 10-17-2005, 09:05 PM
  4. Max number of characters in a cell
    By Dajana in forum Excel General
    Replies: 1
    Last Post: 09-25-2005, 06:05 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