+ Reply to Thread
Results 1 to 2 of 2

Removing user-specific characters from data

Hybrid View

  1. #1
    Registered User
    Join Date
    03-01-2012
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2010
    Posts
    64

    Smile Removing user-specific characters from data

    Hello Everybody

    I've been playing with this problem now for a little while and am getting nowhere fast so any help is very much appreciated!

    I've uploaded an example spreadsheet of the problem I'm trying to solve - I'm trying to set up a model in Excel for cleaning data, which allows the user to enter into a column the characters that they want to remove from a cell, and the excel functions will then look to see if any of the given characters in this column are present in the data and remove them accordingly.

    I know I could nest multiple SUBSTITUTE functions together but I think the problem with this is knowing how many characters the user may want to look for, ie: if I nest ten together but they want to search for 12 different characters it won't look for the last 2. It needs to allow for the flexibility of the user to enter as many different characters as they want to clean from their data

    If it's any help at all I did see a while ago a way of doing this which if memory serves me correctly enough involved an array function with TRIM and possibly MID, but can I find this now? No...

    I'd prefer not to go down the route of VBA as i need to keep this model relatively simple for use by others

    Can anyone help please?

    Thanks in advance
    Kenny
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    09-18-2012
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Removing user-specific characters from data

    I could only do it via vba code (though in doing it i've solved a problem that's been bugging me for months).

    I'm a total amateur at these things so apologies for the inelegant solution. This counts through text entries down in B3 down (up to a 100) then through your rogue characters in E3 down to row 20 and allows for words up to 20 characters long.

    Sub remove_char()
        Dim word As String
        Dim char As String
        Dim output As String
        Dim index As Integer
        output = ""
        index = 3
        For wordcount = 3 To 100
            If Cells(wordcount, 2).Value <> "" Then
                word = Cells(wordcount, 2).Value
            Else
                wordcount = 100
            End If
            For count1 = 3 To 20
                If Cells(count1, 5).Value <> "" Then
                    char = Cells(count1, 5).Value
                Else
                    count1 = 20
                End If
                For count2 = 1 To Len(word)
                    If Mid(word, count2, 1) = char Then
                        If count2 = 1 Then
                            output = Mid(word, (count2 + 1), Len(word) - count2)
                            count2 = count2 - 1
                        Else
                            output = Mid(word, 1, (count2 - 1)) & Mid(word, (count2 + 1), Len(word) - (Len(word) - count2))
                            count2 = count2 - 1
                        End If
                        word = output
                    End If
                Next count2
            Next count1
            If output = "" Then
                output = word
            End If
            Cells(index, 10).Value = output
            index = index + 1
            output = ""
        Next wordcount
        
    End Sub
    I've done some basic testing - hope it works for you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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