BOnjour à tous
Voici un code qui sert à supprimer les parenthèses de toutes les cellules spécifiées dans la procédure Com.
J'ai une erreur "objet requis" mais je ne sais pas ou ni pourquoi qui se situe normalement dans la procédure Com()?
(la première fonction est correcte, c'est pas la peine de la tester).
Merci à vous
Function ExtractElement(Txt, n, Separator) As String
' Returns the nth element of a text string, where the
' elements
' are separated by a specified separator character
Dim Txt1 As String, temperament As String
Dim ElementCount As Integer, i As Integer
Dim TempElement As String
Txt1 = Txt
' If space separator, remove excess spaces
If Separator = Chr(32) Then Txt1 = Application.Trim(Txt1)
' Add a separator to the end of the string
If Right(Txt1, Len(Txt1)) <> Separator Then _
Txt1 = Txt1 & Separator
' Initialize
ElementCount = 0
TempElement = ""
' Extract each element
For i = 1 To Len(Txt1)
If Mid(Txt1, i, 1) = Separator Then
ElementCount = ElementCount + 1
If ElementCount = n Then
' Found it, so exit
ExtractElement = TempElement
Exit Function
Else
TempElement = ""
End If
Else
TempElement = TempElement & Mid(Txt1, i, 1)
End If
Next i
ExtractElement = ""
End Function
Sub Com()
Dim lg As Variant
For Var = 1 To 10000
For cpt = 1 To 500
lg = Len(Cells(Var, 11))
chaine = WorsheetFunction.ExtractElement(Cells(Var, 11).Value, cpt, "(")
ch = chaine & Right(Cells(Var, 11), lg - 1)
Cells(Var, 12).Value = ch
Next cpt
Next Var
End Sub