Herbers Excel-Forum - das Archiv

Textformat (VBA)


Betrifft: Textformat (VBA)
von: Werner

Geschrieben am: 14.09.2019 05:35:08
Guten Morgen Forum,
Für folgendes benötige ich Hilfe.
https://www.herber.de/bbs/user/132036.xlsm
Wenn in den Zellen der Spalten B ein Text eingegeben wird in dem die Buchstabenkombination VKA als separates "Wort" vorkommt, soll diese Buchstabenkombination automatisch fett (F), in Großbuchstaben und der Farbe RGB R-71, G-71 und B-255 formatiert werden.
Würde mit bitte jemand einen entsprechenden VBA Code zur Verfügung stellen?
Besten Dank und Gruß
Werner

Betrifft: AW: Textformat (VBA)
von: 1713026.html

Geschrieben am: 14.09.2019 10:51:43
Hallo Werner,
ich habe dein Makro entsprechend erweitert:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Zelle As Range
    Dim objRange As Range, objCell As Range
    Dim lngPostition As Long
    Application.EnableEvents = False
    Set objRange = Intersect(Target, Range(Cells(4, 2), Cells(Rows.Count, 2)))
    If Not objRange Is Nothing Then
        For Each objCell In objRange
            lngPostition = InStr(1, objCell.Value, " VKA ", vbTextCompare)
            If lngPostition <> 0 Then
                With objCell.Characters(lngPostition + 1, 3)
                    .Text = UCase$(.Text)
                    .Font.Bold = True
                    .Font.Color = RGB(71, 71, 255)
                End With
            End If
        Next
        Set objRange = Nothing
    End If
    If Not Intersect(Target, Range("C1")) Is Nothing Then
        If Selection.Cells.Count > 1 Then
            For Each Zelle In Selection
                If Zelle.Value = "" Then
                    Zelle.Value = "Enter the style number here."
                End If
            Next
            Exit Sub
        End If
        If Target = "" Then
            Target = "Enter the style number here."
        End If
    End If
    Application.EnableEvents = True
End Sub

Gruß
Nepumuk

Betrifft: AW: Textformat (VBA)
von: 1713050.html
Geschrieben am: 14.09.2019 13:04:25
Hallo Nepumuk,
Vielen Dank für die Mühe welche Du Dir gemacht hast, das ist super :-).
Funktioniert prima.
Gruß
Werner

Bewerten Sie hier bitte das Excel-Portal