Function ChangeAllCellpropertiesInRange(ByRef RnG As Range, prop As String)
Dim R As Variant, Addr
With RnG
Addr = "'" & .Parent.Name & "'!" & .Address
Select Case UCase(prop)
'formule non matricielles
Case "LOWER", "UPPER", "PROPER", "APPTRIM":
prop = Replace(UCase(prop), "APPTRIM", "TRIM")
R = Evaluate("IF(ISTEXT(" & Addr & ")," & UCase(prop) & "(" & Addr & "),REPT(" & Addr & ",1))")
'formules matricielle
Case "LTRIM": R = Evaluate("IF(ISTEXT(" & Addr & "),MID(" & Addr & ",FIND(MID(TRIM(" & Addr & "),1,2)," & Addr & ",1),LEN(" & Addr & ")),REPT(" & Addr & ",1))")
'ancienne formule RTRIM qui fonctionne
'Case "RTRIM": R = Evaluate("IF(ISTEXT(" & Addr & "),LEFT(" & Addr & ",FIND(""^^"",SUBSTITUTE(" & Addr & ",RIGHT(TRIM(" & Addr & "),1),""^^"",LEN(" & Addr & ")-LEN(SUBSTITUTE(" & Addr & ",RIGHT(TRIM(" & Addr & "),1),""""))))),REPT(" & .Address & ",1))")
'nouvelle formule
Case "RTRIM": R = Evaluate("IF(ISTEXT(" & Addr & "),LEFT(" & Addr & ",FIND(""§"",SUBSTITUTE(" & Addr & ",RIGHT(TRIM(" & Addr & "),1),""§"",LEN(" & Addr & ")-LEN(SUBSTITUTE(" & Addr & ",RIGHT(TRIM(" & Addr & "),1),""""))),1))," & Addr & ")")
Case "TRIM":
.Value = Evaluate("IF(ISTEXT(" & .Address & "),MID(" & .Address & ",FIND(MID(TRIM(" & .Address & "),1,2)," & .Address & ",1),LEN(" & .Address & ")),REPT(" & .Address & ",1))")
R = Evaluate("IF(ISTEXT(" & .Address & "),MID(" & .Address & ",1,FIND(TRIM(RIGHT(SUBSTITUTE(TRIM(" & .Address & "), "" "", REPT("" "", 100)), 100))," & .Address & ",1)+LEN(TRIM(RIGHT(SUBSTITUTE(TRIM(" & .Address & "), "" "", REPT("" "", 100)), 100)))-1),REPT(" & .Address & ",1))")
End Select
End With
ChangeAllCellpropertiesInRange = R
End Function
Sub testxx()
[C1:C100000] = " kldefkrei efjfr edferjgf "
End Sub
Sub test()
Dim DL, RnG As Range, tim&
With Sheets(1)
DL = .Cells(Rows.Count, 3).End(xlUp).Row
Set RnG = .Range("C1:C" & DL)
tim = Timer
RnG.Value = ChangeAllCellpropertiesInRange(RnG, "trim") 'majuscule ou minuscule l'argument de propertie
End With
MsgBox Format(Timer - tim, "#0.00") 'message du temps passé a convertir
End Sub