Anzeige
Archiv - Navigation
1764to1768
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Weitersuchen mit CommandButton

Weitersuchen mit CommandButton
09.06.2020 21:18:06
Marco
Hallo Zusammen,
ich habe eine Userform mit mehreren Textboxen und einen CommandButton für die Suche. Sobald ich in einer TextBox einen Suchbegriff eingebe sollen alle Daten aus der Tabelle in die restlichen Textboxen geschrieben werden. Das funktioniert auch so weit aber wenn es mehre Ergebnisse gibt soll diese mit erneuten Betätigung des Buttons abgerufen und in die Textboxen überschrieben werden. Leider funktioniert das nicht. Ich hoffe es kann mir jemand helfen denn ich bin am verzweifeln. Schön wäre es wenn beim letzten gefunden Datensatz eine MsgBox angezeigt wird. Vielen Dank.

Private Sub CommandButton4_Click()
Dim rZelle As Object
Dim firstAddress As String
If TextBox46.Value = "" Then
MsgBox "Bitte eine Eingabe tätigen!", 48, "   Hinweis für " & Application.UserName
TextBox46.SetFocus
End If
If TextBox46.Value  "" Then
With Worksheets("Gesamt")
Set rZelle = Range(Columns(1), Columns(42)).Find("*" & TextBox46 & "*", MatchCase:=False,  _
_
_
_
LookAt:=xlWhole, LookIn:=xlValues)
If Not rZelle Is Nothing Then
firstAddress = rZelle.Address
Do
TextBox1.Value = .Cells(rZelle.Row, 1).Value
TextBox2.Value = .Cells(rZelle.Row, 2).Value
TextBox7.Value = .Cells(rZelle.Row, 7).Value
TextBox44.Value = .Cells(rZelle.Row, 3).Value
TextBox13.Value = .Cells(rZelle.Row, 4).Value
TextBox5.Value = .Cells(rZelle.Row, 5).Value
TextBox6.Value = .Cells(rZelle.Row, 6).Value
ComboBox1.Value = .Cells(rZelle.Row, 9).Value
TextBox8.Value = .Cells(rZelle.Row, 10).Value
TextBox9.Value = .Cells(rZelle.Row, 11).Value
TextBox10.Value = .Cells(rZelle.Row, 12).Value
TextBox11.Value = .Cells(rZelle.Row, 13).Value
TextBox12.Value = .Cells(rZelle.Row, 14).Value
TextBox21.Value = .Cells(rZelle.Row, 15).Value
TextBox14.Value = .Cells(rZelle.Row, 16).Value
TextBox15.Value = .Cells(rZelle.Row, 17).Value
TextBox16.Value = .Cells(rZelle.Row, 18).Value
TextBox17.Value = .Cells(rZelle.Row, 19).Value
TextBox18.Value = .Cells(rZelle.Row, 20).Value
TextBox19.Value = .Cells(rZelle.Row, 21).Value
TextBox20.Value = .Cells(rZelle.Row, 22).Value
TextBox22.Value = .Cells(rZelle.Row, 23).Value
TextBox23.Value = .Cells(rZelle.Row, 24).Value
TextBox25.Value = .Cells(rZelle.Row, 25).Value
TextBox31.Value = .Cells(rZelle.Row, 26).Value
TextBox26.Value = .Cells(rZelle.Row, 42).Value
TextBox32.Value = .Cells(rZelle.Row, 28).Value
TextBox28.Value = .Cells(rZelle.Row, 36).Value
TextBox29.Value = .Cells(rZelle.Row, 40).Value
TextBox30.Value = .Cells(rZelle.Row, 41).Value
TextBox27.Value = .Cells(rZelle.Row, 27).Value
TextBox33.Value = .Cells(rZelle.Row, 29).Value
TextBox34.Value = .Cells(rZelle.Row, 30).Value
TextBox35.Value = .Cells(rZelle.Row, 31).Value
TextBox36.Value = .Cells(rZelle.Row, 32).Value
TextBox37.Value = .Cells(rZelle.Row, 33).Value
TextBox38.Value = .Cells(rZelle.Row, 34).Value
TextBox24.Value = .Cells(rZelle.Row, 35).Value
TextBox39.Value = .Cells(rZelle.Row, 37).Value
TextBox40.Value = .Cells(rZelle.Row, 38).Value
TextBox41.Value = .Cells(rZelle.Row, 39).Value
Set rZelle = Range(Columns(1), Columns(42)).FindNext(rZelle)
Loop While rZelle.Address  firstAddress
Else
MsgBox "Die gesuchte EIngabe:  """ & TextBox46 & """  wurde nicht gefunden!", 48, "      _
_
_
_
Hinweis für " & Application.UserName
TextBox46.SetFocus
End If
End With
End If
End Sub

5
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Weitersuchen mit CommandButton
09.06.2020 23:20:14
ralf_b
ich habe vor einiger Zeit etwas ähnliches gebaut.
dort nutze ich eine listbox, in welche ich die suchergebnisse(passende Zeilen) mittels schleife und additem untereinander schreibe.
wenn dann auf einen der Werte geklickt wird, schreibe ich die restlichen, zugehörigen werte in verschiedene Textboxen, Dropdowns, Optionbuttons
evtl für dich ein Ansatz das Problem anzugehen.
jedes mal wenn du den button drückst löschst du den wert in rZelle und fängst von vorne an. entweder du definierst dir diese Variable außerhalb und vergleichst bei jeden buttonclick den wert, oder du benötigst einen Zwischenschritt z.b. über meine obige Lösung.
Anzeige
AW: Weitersuchen mit CommandButton
10.06.2020 06:36:52
Marco
Guten Morgen Ralf,
vielen Dank für deine schnelle Antwort.
Wie würde denn der Code aussehen wenn ich die Variable außerhalb definieren möchte?
Hast du da eine Lösung für mich?
AW: Weitersuchen mit CommandButton
10.06.2020 14:16:06
ralf_b
versuch mal das. war doch etwas mehr zu tun. ist ungetestet und somit wahrscheinlich nicht fehlerfrei. besser du lädst beispieldateien hoch. die arbeit solltest du dir schon machen wenn man dir den rest abnehmen soll.
Dim lastcellAddress As String
Private Sub CommandButton4_Click()
Dim rZelle As Object
If TextBox46.Value = "" Then
MsgBox "Bitte eine Eingabe tätigen!", 48, "   Hinweis für " & Application.UserName
TextBox46.SetFocus
Exit Sub
End If
With Worksheets("Gesamt")
If lastcellAddress = "" Then
Set rZelle = Range(.Columns(1), .Columns(42)).Find("*" & TextBox46 & "*", MatchCase:= _
False, LookAt:=xlWhole, LookIn:=xlValues)
If Not rZelle Is Nothing Then
lastcellAddress = rZelle.Address
Else
MsgBox "Die gesuchte Eingabe:  """ & TextBox46 & """  wurde nicht gefunden!", 48,  _
" Hinweis für " & Application.UserName
TextBox46.SetFocus
Exit Sub
End If
Else
Set rZelle = Range(.Columns(1),.Columns(42)).FindNext(.Range(lastcellAddress))
If Not rZelle Is Nothing Then
lastcellAddress = rZelle.Address
Else
MsgBox "Keine weiteren Ergebnisse vorhanden", 48, " Hinweis für " & Application. _
UserName
TextBox46.SetFocus
Exit Sub
End If
End If
textboxen_fuellen .Name, rZelle.Row
End With
Set rZelle = Nothing
End Sub
Private Function textboxen_fuellen(wks As String, zeile As Long)
With Worksheets(wks)
TextBox1.Value = .Cells(zeile, 1).Value
TextBox2.Value = .Cells(zeile, 2).Value
TextBox7.Value = .Cells(zeile, 7).Value
TextBox44.Value = .Cells(zeile, 3).Value
TextBox13.Value = .Cells(zeile, 4).Value
TextBox5.Value = .Cells(zeile, 5).Value
TextBox6.Value = .Cells(zeile, 6).Value
ComboBox1.Value = .Cells(zeile, 9).Value
TextBox8.Value = .Cells(zeile, 10).Value
TextBox9.Value = .Cells(zeile, 11).Value
TextBox10.Value = .Cells(zeile, 12).Value
TextBox11.Value = .Cells(zeile, 13).Value
TextBox12.Value = .Cells(zeile, 14).Value
TextBox21.Value = .Cells(zeile, 15).Value
TextBox14.Value = .Cells(zeile, 16).Value
TextBox15.Value = .Cells(zeile, 17).Value
TextBox16.Value = .Cells(zeile, 18).Value
TextBox17.Value = .Cells(zeile, 19).Value
TextBox18.Value = .Cells(zeile, 20).Value
TextBox19.Value = .Cells(zeile, 21).Value
TextBox20.Value = .Cells(zeile, 22).Value
TextBox22.Value = .Cells(zeile, 23).Value
TextBox23.Value = .Cells(zeile, 24).Value
TextBox25.Value = .Cells(zeile, 25).Value
TextBox31.Value = .Cells(zeile, 26).Value
TextBox26.Value = .Cells(zeile, 42).Value
TextBox32.Value = .Cells(zeile, 28).Value
TextBox28.Value = .Cells(zeile, 36).Value
TextBox29.Value = .Cells(zeile, 40).Value
TextBox30.Value = .Cells(zeile, 41).Value
TextBox27.Value = .Cells(zeile, 27).Value
TextBox33.Value = .Cells(zeile, 29).Value
TextBox34.Value = .Cells(zeile, 30).Value
TextBox35.Value = .Cells(zeile, 31).Value
TextBox36.Value = .Cells(zeile, 32).Value
TextBox37.Value = .Cells(zeile, 33).Value
TextBox38.Value = .Cells(zeile, 34).Value
TextBox24.Value = .Cells(zeile, 35).Value
TextBox39.Value = .Cells(zeile, 37).Value
TextBox40.Value = .Cells(zeile, 38).Value
TextBox41.Value = .Cells(zeile, 39).Value
End With
End Function

Anzeige
AW: Weitersuchen mit CommandButton
10.06.2020 21:06:59
Marco
leider hat es nicht den gewünschten Erfolg gebracht trotzdem Danke ich dir für deine Mühe. Ich habe mittlerweile anderweitig einen Code erhalten der funktioniert. Ich möchte diesen hier teilen falls mal jemand vor dem selben Problem steht.
Private Sub CommandButton4_Click()
Static rZelle As Object
Static firstAddress As String
If firstAddress = "" Then
If TextBox46.Value = "" Then
MsgBox "Bitte eine Eingabe tätigen!", 48, "  Hinweis für " & Application.UserName
TextBox46.SetFocus
Else
With Worksheets("Gesamt")
Set rZelle = .Range(.Columns(1), .Columns(42)).Find( _
What:="*" & TextBox46 & "*", _
MatchCase:=False, _
LookAt:=xlWhole, _
LookIn:=xlValues)
End With
If Not rZelle Is Nothing Then
firstAddress = rZelle.Address
Else
MsgBox "Die gesuchte EIngabe:  """ & TextBox46 & """  wurde nicht gefunden!", _
48, " Hinweis für " & Application.UserName
TextBox46.SetFocus
End If
End If
Else
With Worksheets("Gesamt")
Set rZelle = .Range(.Columns(1), .Columns(42)).FindNext(rZelle)
End With
End If
If Not rZelle Is Nothing Then
If rZelle.Address  firstAddress Or Me.Tag = "" Then
With Worksheets("Gesamt")
TextBox1.Value = .Cells(rZelle.Row, 1).Value
TextBox2.Value = .Cells(rZelle.Row, 2).Value
TextBox44.Value = .Cells(rZelle.Row, 3).Value
TextBox13.Value = .Cells(rZelle.Row, 4).Value
TextBox5.Value = .Cells(rZelle.Row, 5).Value
TextBox6.Value = .Cells(rZelle.Row, 6).Value
TextBox7.Value = .Cells(rZelle.Row, 7).Value
ComboBox1.Value = .Cells(rZelle.Row, 9).Value
TextBox8.Value = .Cells(rZelle.Row, 10).Value
TextBox9.Value = .Cells(rZelle.Row, 11).Value
TextBox10.Value = .Cells(rZelle.Row, 12).Value
TextBox11.Value = .Cells(rZelle.Row, 13).Value
TextBox12.Value = .Cells(rZelle.Row, 14).Value
TextBox21.Value = .Cells(rZelle.Row, 15).Value
TextBox14.Value = .Cells(rZelle.Row, 16).Value
TextBox15.Value = .Cells(rZelle.Row, 17).Value
TextBox16.Value = .Cells(rZelle.Row, 18).Value
TextBox17.Value = .Cells(rZelle.Row, 19).Value
TextBox18.Value = .Cells(rZelle.Row, 20).Value
TextBox19.Value = .Cells(rZelle.Row, 21).Value
TextBox20.Value = .Cells(rZelle.Row, 22).Value
TextBox22.Value = .Cells(rZelle.Row, 23).Value
TextBox23.Value = .Cells(rZelle.Row, 24).Value
TextBox25.Value = .Cells(rZelle.Row, 25).Value
TextBox31.Value = .Cells(rZelle.Row, 26).Value
TextBox26.Value = .Cells(rZelle.Row, 42).Value
TextBox32.Value = .Cells(rZelle.Row, 28).Value
TextBox28.Value = .Cells(rZelle.Row, 36).Value
TextBox29.Value = .Cells(rZelle.Row, 40).Value
TextBox30.Value = .Cells(rZelle.Row, 41).Value
TextBox27.Value = .Cells(rZelle.Row, 27).Value
TextBox33.Value = .Cells(rZelle.Row, 29).Value
TextBox34.Value = .Cells(rZelle.Row, 30).Value
TextBox35.Value = .Cells(rZelle.Row, 31).Value
TextBox36.Value = .Cells(rZelle.Row, 32).Value
TextBox37.Value = .Cells(rZelle.Row, 33).Value
TextBox38.Value = .Cells(rZelle.Row, 34).Value
TextBox24.Value = .Cells(rZelle.Row, 35).Value
TextBox39.Value = .Cells(rZelle.Row, 37).Value
TextBox40.Value = .Cells(rZelle.Row, 38).Value
TextBox41.Value = .Cells(rZelle.Row, 39).Value
End With
Me.Tag = "x"
TextBox46.Enabled = False
Else
MsgBox "Das wars"
Set rZelle = Nothing
firstAddress = ""
Me.Tag = ""
TextBox46.Enabled = True
End If
End If
End Sub

Anzeige
AW: Weitersuchen mit CommandButton
10.06.2020 13:58:17
Marco
Bräuchte hier auf jedenfall noch Hilfe

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige