Macro pour supprimer du texte entre parenthèses...

Christian0258

XLDnaute Accro
Bonjour à tout le forum,

Je souhaiterais votre aide afin d'écrire une macro pour effacer du texte en parenthèses sous conditions...

voir fichier.

Je vous remercie, par avance, pour le temps que vous voudrez bien, à nouveau, m'accorder.

Bien amicalement,
Christian
 

Pièces jointes

  • Supprimer texte entre parenthèses.xls
    25.5 KB · Affichages: 85

david84

XLDnaute Barbatruc
Re : Macro pour supprimer du texte entre parenthèses...

Bonjour,
à tester :
Code:
Sub test()
Dim c As Range
For Each c In Selection
c.Replace what:="(", Replacement:=""
c.Replace what:=")", Replacement:=""
Next c
End Sub
Avec la condition "MIDI" :
Code:
Sub test()
Dim c As Range
For Each c In Selection
If c.Offset(0, -3) = "MIDI" Then
c.Replace what:="(", Replacement:=""
c.Replace what:=")", Replacement:=""
End If
Next c
End Sub
A+
 
Dernière édition:

KenDev

XLDnaute Impliqué
Re : Macro pour supprimer du texte entre parenthèses...

Bonjour Christian, David,

Sauf erreur la solution précédente n'efface pas le contenu des parenthèses ?

Cordialement

KD

Une autre solution avec choix midi ou soir ou les deux demandé
VB:
Option Explicit

Sub EffPar()
Dim Opt As String, i As Long
Worksheets("Feuil1").Activate
Opt = Application.InputBox("Entrez M ou S (autre entrée ou Annuler = M ET S)", "Catégorie à traiter", , , , , , 2)
Opt = IIf(Opt = "M", "MIDI", IIf(Opt = "S", "SOIR", "TOUS"))
If Opt = "TOUS" Then
    Range(Cells(2, 6), Cells(Cells(Rows.Count, 6).End(xlUp).Row, 6)).Replace What:=" (*)", Replacement:=""
Else
    For i = 2 To Cells(Rows.Count, 6).End(xlUp).Row
        If Cells(i, 3) = Opt Then Cells(i, 6).Replace What:=" (*)", Replacement:=""
    Next i
End If
End Sub
 

job75

XLDnaute Barbatruc
Re : Macro pour supprimer du texte entre parenthèses...

Bonjour à tous,

Voir le fichier joint avec cette macro qui utilise le filtre automatique :

Code:
Sub SupprimerParentheses()
Dim rep$, plage As Range
1 rep = InputBox("Entrez MIDI ou SOIR, TOUT pour traiter les deux :")
If rep = "" Then Exit Sub
If rep <> "MIDI" And rep <> "SOIR" And rep <> "TOUT" Then GoTo 1
Application.ScreenUpdating = False
Set plage = Range("C1", [C65536].End(xlUp))
If rep <> "TOUT" Then plage.AutoFilter 1, rep
Set plage = Intersect(plage.SpecialCells(xlCellTypeVisible).EntireRow, [F:F])
ActiveSheet.AutoFilterMode = False
plage.Replace " (*)", "", xlPart
End Sub
A+
 

Pièces jointes

  • Supprimer texte entre parenthèses(1).xls
    46 KB · Affichages: 76

david84

XLDnaute Barbatruc
Re : Macro pour supprimer du texte entre parenthèses...

Re
Sauf erreur la solution précédente n'efface pas le contenu des parenthèses
c'est exact, je n'avais pas tout compris.
Donc, nouveau code à tester (pour "MIDI"):
Code:
Sub test()
Dim c As Range, pos1&, pos2&
For Each c In Selection
    If c.Offset(0, -3) = "MIDI" Then
    pos1 = InStr(c, "(")
    pos2 = InStr(c, ")")
        If pos1 > 0 Then
            If pos2 = Len(c) Then
                c = Left(c, pos1 - 1)
            Else
                c = Left(c, pos1 - 2) & Right(c, Len(c) - pos2)
            End If
        End If
    End If
Next c
End Sub
A+
 

Discussions similaires