Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

XL 2016 Texte en gras d'une cellule extrait

Bastien43

XLDnaute Occasionnel
Bonjour,

Je cherche à extraire d'une cellule le texte en gras uniquement. Dans cette cellule, il peut y avoir du texte non gras, avec d'autres formats, des alinéa, etc.

Comment extraire uniquement le texte en gras svp ? Quel serait le code de la fonction ?

Est-ce possible ? J'avais trouvé ceci mais cela ne fonctionne pas.


VB:
Function GetBold(pWorkRng As Range)
If pWorkRng.Font.Bold Then
    GetBold = pWorkRng.Value
Else
    GetBold = ""
End If
End Function

Merci
Cordialement
 
Solution
Bonsoir Bastien43;
VB:
Function TrouveGras$(c As Range)
Application.Volatile 'touche F9 pour mettre à jour
Dim i%
For i = 1 To Len(c)
    With c.Characters(i, 1)
        If .Font.Bold Then TrouveGras = TrouveGras & .Text
    End With
Next
End Function
Bonne nuit.

Bastien43

XLDnaute Occasionnel
J'ai trouvé ca, c'est pas le mieux je pense mais ca fonctionne


VB:
 Public Function findAllBold(ByVal rngText As Range) As String
    Dim theCell As Range
    Set theCell = rngText.Cells(1, 1)

    For i = 1 To Len(theCell.Value)
        If theCell.characters(i, 1).Font.Bold = True Then
            If theCell.characters(i + 1, 1).Text = " " Then
                theChar = theCell.characters(i, 1).Text '& " "
                Else
                theChar = theCell.characters(i, 1).Text
            End If
            Results = Results & theChar
        End If
   Next i
   findAllBold = Results
End Function
 

job75

XLDnaute Barbatruc
Bonsoir Bastien43;
VB:
Function TrouveGras$(c As Range)
Application.Volatile 'touche F9 pour mettre à jour
Dim i%
For i = 1 To Len(c)
    With c.Characters(i, 1)
        If .Font.Bold Then TrouveGras = TrouveGras & .Text
    End With
Next
End Function
Bonne nuit.
 

Discussions similaires

Réponses
3
Affichages
301
Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…