Hilfe bei Makroumstellung _ Text _Hervorheben
09.01.2005 16:45:05
Sonnenpeter
Matthias hat mir diese Makro's geschrieben, die auch funktionieren.
Nun mein Probblem.
Ich wollte es umschreiben und eine Inputbox einbauen, da ich nicht nur Firmennamen sondern auch Stadtnamen etc, fett hervorheben will/soll.
Jetzt muss ich jedesmal in VBA und die Constante entsprechend ändern -(
Wenn ich die Inputbox einbaue wird "finde" als Constante gefordert und ende der Fahnenstange.
'finde = InputBox("Suchbegriff eingeben", "Eingabe")
Habe ihr eine Lösung?
Gruß / Sonnenpeter
Option Explicit
Sub SchreibeFett()
Const finde = "Firma Müller" 'könnte auch "Fr. Müller sein ober Musterstadt etc.
'Dim finde
Dim found As Range
Dim firstaddress As String
'finde = InputBox("Suchbegriff eingeben", "Eingabe")
Set found = Cells.Find(What:=finde, LookIn:=xlValues, LookAt _
:=xlPart, MatchCase:=False)
If Not found Is Nothing Then
firstaddress = found.Address
Do
Machfett found, finde
Set found = Cells.FindNext(found)
Loop While Not found Is Nothing And found.Address <> firstaddress
End If
End Sub
Sub Machfett(z As Range, f As String)
Dim z0 As String
Dim fx As Long, start As Long
z0 = z.Value
start = 1
fx = InStr(start, z0, f)
Do While fx > 0
With z.Characters(start:=fx, Length:=Len(f)).Font
.FontStyle = "Fett"
.ColorIndex = 5
End With
start = start + Len(f)
fx = InStr(start, z0, f)
Loop
End Sub