Home » excel » excel – Combining formulas

excel – Combining formulas

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have this formula in a table which basically collects data from two columns and combines them. Now, I’m looking to combine this formula with a REPLACE formula that basically takes these characters æ,ø,å and replaces them with a,o,a.

Here’s the formula:

=LOWER(LEFT(tableFaste[[#This Row];[Fornavn:]])&tableFaste[[#This Row];[Etternavn:]])
How to&Answers:

You can use SUBSTITUTE

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(LOWER(LEFT(tableFaste[[#This Row];[Fornavn:]])&tableFaste[[#This Row];[Etternavn:]]),"æ","a"),"ø","o"),"å","a")

Answer:

Sorry, don’t know of a Formula way to remove any of a list of characters from a string. You might have to revert to vba for this. Here’s a user defined function to do it. Your formula will become

=DeleteChars([@UserName],{"æ","ø","å";"a","o","a"})

To replace the characters use {“æ”,”ø”,”å”;”a”,”o”,”a”} where the list up to the ; is the old characters, after the ; the new. You can make the list as long as you need, just make sure the lists are the same length.
To Delete the characters replace use {“æ”,”ø”,”å”} an array list of characters you want to remove

UDF code:

Function DeleteChars(r1 As Range, ParamArray c() As Variant) As Variant
    Dim i As Long
    Dim s As String

    s = r1
    If UBound(c(0), 1) = 1 Then
        For i = LBound(c(0), 2) To UBound(c(0), 2)
            s = Replace(s, c(0)(1, i), "")
        Next
    Else
        For i = LBound(c(0), 2) To UBound(c(0), 2)
            s = Replace(s, c(0)(1, i), c(0)(2, i))
        Next
    End If
    DeleteChars = s
End Function