Consulting

Results 1 to 3 of 3

Thread: Need a UDF to Identify and remove parts of Cell Data from a Range

  1. #1
    VBAX Regular
    Joined
    Apr 2017
    Posts
    32
    Location

    Need a UDF to Identify and remove parts of Cell Data from a Range

    Hi Good Morning from Sri Lanka,

    I have sets of words in cell A1,A2,A3 in Sheet 1

    I have a Range which I look to remove from above Cells (plus I will continue to update that Colomn), They are in Sheet 2, Colomn 4 (ex for words are - Trusted User, Call Now, Sale)

    Now I need the following to happen:

    A1 = ABC Company Trusted User

    Result in B1 = ABC Company

    A2 = ABC Company Sale

    Result in B2 = ABC Company

    A3 = JnH Users and Distributors Call Now

    Result in B3 = JnH Users and Distributors

    Is this possible?

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Try this. Attachment has some sample data


    Option Explicit
    Function RemoveWords(s As String, r As Range) As String
        Dim r1 As Range
        Dim s1 As String
        
        s1 = s
        
        For Each r1 In r.Cells
            If Len(r1.Text) = 0 Then Exit For
            s1 = Trim(Replace(s1, r1.Text, vbNullString))
        Next
        
        RemoveWords = s1
        
    End Function
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Regular
    Joined
    Apr 2017
    Posts
    32
    Location
    Quote Originally Posted by Paul_Hossler View Post
    Try this. Attachment has some sample data


    Option Explicit
    Function RemoveWords(s As String, r As Range) As String
        Dim r1 As Range
        Dim s1 As String
        
        s1 = s
        
        For Each r1 In r.Cells
            If Len(r1.Text) = 0 Then Exit For
            s1 = Trim(Replace(s1, r1.Text, vbNullString))
        Next
        
        RemoveWords = s1
        
    End Function
    Awesome Chief, Thanks alot. May Lord Mighty of All Words Bless you. Ameen.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •