+ Reply to Thread
Results 1 to 11 of 11

Format individual strings out of multiple strings within a cell with VBA

  1. #1
    Forum Contributor
    Join Date
    04-15-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2016 / Office 365
    Posts
    115

    Format individual strings out of multiple strings within a cell with VBA

    I am using the macro below to transfer data from a form to a matrix. Some of the fields on the form are being combined into one cell within the matrix this all works great. Now I need to try and format specific words within the combined cell. Some will be formatted as text and some will be formatted as bold. For example Cells B1, B2, and B5 are being combined into once cell. I need to italicize B1 and Bold B5 within the one cell of the matrix so that they look like this in the matrix.
    Value of B1
    Value of B2
    Value of B5

    I was trying to store the values of the cells that I need to have formatted as variables and then use the Find function to locate the word in the cell after the transfer but had no luck figuring it out. I also tried to format the value of the cell and store it as a variable with the formatting but that was not working either. Copy and Paste wont work because the Form does not contain any formatting.

    The following Macro is set to work from the Personal Macro Workbook. Comments are included so that co workers no what is going on and how.

    Please Login or Register  to view this content.
    Last edited by jrtraylor; 09-17-2013 at 11:03 PM. Reason: mixed up some of the cell values in the example paragraph

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Format individual strings out of multiple strings within a cell with VBA

    Try this function:
    Please Login or Register  to view this content.

    To use it, it would be something like this:
    Please Login or Register  to view this content.
    Last edited by millz; 09-18-2013 at 02:21 AM. Reason: Amendments to function

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Format individual strings out of multiple strings within a cell with VBA

    Please Login or Register  to view this content.
    Ben Van Johnson

  4. #4
    Forum Contributor
    Join Date
    04-15-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2016 / Office 365
    Posts
    115

    Re: Format individual strings out of multiple strings within a cell with VBA

    Thanks for the help guys, I am almost able to understand both responses.

    Millz
    Your response is working for the most part. When I run the macro, it sets all of the Values from cell B1 and B2 and B5 as italic and then sets the value from B5 Bold.

    ProtonLeah
    Your option is also working for the most part. When I run the macro, it sets part of the Value from B1 to Italic (The First 12 Characters) and then it sets the remaining characters from B1 that were not italicized as Bold along with the values from B2 and B5.

    I will transfer my code to buttons on a worksheet and get examples of the 2 workbooks I am using loaded to show how the options provided are reacting on my end. One thing I should mention, is I will have to use this same functionality on some of the other cells in the rest of the code.

  5. #5
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Format individual strings out of multiple strings within a cell with VBA

    Quote Originally Posted by jrtraylor View Post
    Millz
    Your response is working for the most part. When I run the macro, it sets all of the Values from cell B1 and B2 and B5 as italic and then sets the value from B5 Bold.
    I just tested a little, the code is working fine (at least for me). It seems that it's working but for your case, because the first character gets italicized, the next time a new value is entered into the cell, the entire cell becomes (stayed, rather) italicized.

    One way is to do this:
    Please Login or Register  to view this content.
    Could be troublesome having to reset italic/bold each time but I guess that's necessary. You can just add them directly into the function if needed anyway, your choice.

  6. #6
    Forum Contributor
    Join Date
    04-15-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2016 / Office 365
    Posts
    115

    Re: Format individual strings out of multiple strings within a cell with VBA

    Here are the 2 workbooks I am working from. Open the matrix upload first then the form upload. The form upload has 3 buttons for the 3 different macros (original from above, millz, and protonleah)

    The matrix has the first row of data that identifies how I need the cell to look, the other 3 rows are the macro xfrs. I will need to be able to duplicate this in some other cells as well. Please note that these files are currently saved in compatibility mode but I am using office 2013. Not all computers have been updated to office 2013 yet.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    04-15-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2016 / Office 365
    Posts
    115

    Re: Format individual strings out of multiple strings within a cell with VBA

    Millz,
    It seems I posted after you had already corrected it. thanks that works just fine.

  8. #8
    Forum Contributor
    Join Date
    04-15-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2016 / Office 365
    Posts
    115

    Re: Format individual strings out of multiple strings within a cell with VBA

    Millz, so if I want to use this same function later in the code on the section below,
    Please Login or Register  to view this content.
    Would I be able to do this as well?
    Please Login or Register  to view this content.

  9. #9
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Format individual strings out of multiple strings within a cell with VBA

    Yes you can just test it. If you know you will be always 'resetting' the format before formatting italic/bold you can add into the function like this:

    Please Login or Register  to view this content.
    Then run it with:
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    04-15-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2016 / Office 365
    Posts
    115

    Re: Format individual strings out of multiple strings within a cell with VBA

    Millz,
    Thanks again, I really need to learn about functions. Would you be able to tell me how I can extract the a string in a cell based on carriage returns or should I start another thread? If you look at the two workbooks I posted, there are 3 cells in the form that identify transferring only a company name from the information. The company name in the cells is either the 2nd string or the 3rd string where each string is separated by a carriage return.
    Thanks again for the help

  11. #11
    Forum Contributor
    Join Date
    04-15-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2016 / Office 365
    Posts
    115

    Re: Format individual strings out of multiple strings within a cell with VBA

    Millz,
    I figured out how to write a function that would extract a specified string between characters, I add it with your function above and I have a wonderful little program.

    Thanks a million.

+ 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. excel formula to search Multiple strings in several columns and return strings
    By krratna123 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-13-2013, 11:20 AM
  2. Replies: 1
    Last Post: 08-13-2013, 08:32 AM
  3. [SOLVED] vlookup individual strings of text within a cell
    By dougdrex in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-20-2013, 03:48 PM
  4. Replies: 3
    Last Post: 05-28-2011, 01:43 PM
  5. Assining individual values to multiple identical strings
    By vivavilla in forum Excel General
    Replies: 1
    Last Post: 03-08-2011, 07:58 AM

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