+ Reply to Thread
Results 1 to 5 of 5

Apply function to selected cells.

  1. #1
    Registered User
    Join Date
    06-04-2011
    Location
    Duluth, MN
    MS-Off Ver
    Excel 2010
    Posts
    15

    Smile Apply function to selected cells.

    I have a custom function called Sentence(). It will capitalize the first letter of the first word of every sentence in a cell and turn everything else into lower case.

    Currently I have to make a separate sheet and link to the cell I want to apply it to. However, Id like to make a macro that will apply this function to a selection of cells. This should be fairly simple but I haven't had much luck making it work by my self.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,422

    Re: Apply function to selected cells.

    It might generate more help if you share the function and a sample workbook.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


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

    Re: Apply function to selected cells.

    Hi dymention2,

    Select the range where you wish to apply the formula (use ctrl key to select if the range is breaking / separate from each other). and press ctrl + Enter.. thanks.

    Regards,
    DILIPandey


    <click on below 'star' if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), [email protected]

  4. #4
    Registered User
    Join Date
    06-04-2011
    Location
    Duluth, MN
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Apply function to selected cells.

    It might generate more help if you share the function and a sample workbook.

    Regards, TMS

    Here is the example spreadsheet: Sentence Function Example.xlsm

    Here is the function:

    Function Sentence(ByVal txt As String) As String
    Dim m As Object
    txt = LCase(txt)
    txt = Application.Replace(txt, 1, 1, UCase(Left$(txt, 1)))
    With CreateObject("VBScript.RegExp")
    .Pattern = "\.\s."
    .Global = True
    For Each m In .Execute(txt)
    txt = Application.Replace(txt, m.FirstIndex + 1, m.Length, UCase(m.Value))
    Next
    End With
    Sentence = txt
    End Function
    Last edited by dymention2; 05-13-2012 at 11:29 AM.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,422

    Re: Apply function to selected cells.

    Thanks for the sample and code ... please note that the forum rules state that you need to use code tags around your code snippets.

    I'll try and have a look in the meantime but cannot respond until you add the tags.

    Regards, TMS

+ 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