MsgBox mit if
15.05.2021 11:07:00
oraculix
Ich habe eine Suchabfrage mit einer MsgBox wenn nichts gefunden dann wird diese angezeigt.
und das Makro Wechselt aber trotzdem in eine andere Tabelle als ich gerne hätte.
Ich bräuchte sowas wie eine if abfrage zb. wenn kein Treffer dann in in Tabelle "FilmDb" aktivieren
ansonst
Tabelle "Gefunden" aktivieren
Weis leider nicht wie ich das in das Makro einbauen kann?
kann mir jemand helfen?
Danke
'In Tabelle FilmDB wird in Spalte A,B und H Gesucht Nach dem suchen wird in Tabelle "Gefunden" der gesuchte Eintrag gelistet.
Public Sub FilmDBFindenUndKopieren()
Worksheets("FilmDB").Activate
Dim iRowT As Long
Dim sWord As String, strFirstAddress As String
Dim objCell As Range
Dim objDictionary As Object
sWord = InputBox(Prompt:="Suchbegriff:", Default:="Filmname")
If sWord vbNullString Then
Set objDictionary = CreateObject(Class:="Scripting.Dictionary")
iRowT = 3
With Worksheets("Gefunden")
Set objCell = Union(Columns("A:B"), Columns("H")).Find(What:=sWord, _
LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False)
If Not objCell Is Nothing Then
strFirstAddress = objCell.Address
Do
If Not objDictionary.Exists(Key:=CStr(objCell.Row)) Then
objDictionary.Item(Key:=CStr(objCell.Row)) = vbNullString
objCell.EntireRow.Copy .Cells(iRowT, 1)
iRowT = iRowT + 1
End If
Set objCell = Union(Columns("A:B"), Columns("H")).FindNext(After:=objCell)
Loop Until objCell.Address = strFirstAddress
Set objCell = Nothing
Set objDictionary = Nothing
.Activate
.UsedRange.Font.Size = 14
With .Range("A2:J5000")
.Font.Color = RGB(255, 192, 0)
.Interior.Color = vbBlack
.Borders.Color = RGB(255, 192, 0)
End With
End If
End With
End If
Worksheets("Gefunden").Activate
Columns("A:A").ColumnWidth = 40.28
If iRowT > 3 Then
Worksheets("Gefunden").Activate
Columns("A:A").ColumnWidth = 40.28
Else
Call MsgBox("Nichts gefunden.", vbInformation, "Information")
End If
Application.ScreenUpdating = True
End Sub