Thema Datum  Von Nutzer Rating
Antwort
Rot Listbox um Funktion erweitern
06.09.2017 17:33:12 Hatsch
NotSolved
07.09.2017 16:06:46 Mackie
NotSolved

Ansicht des Beitrags:
Von:
Hatsch
Datum:
06.09.2017 17:33:12
Views:
1177
Rating: Antwort:
  Ja
Thema:
Listbox um Funktion erweitern
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<span style="color: rgb(51, 51, 51); font-family: Tahoma, Verdana, Arial, sans-serif; font-size: 14px; background-color: rgb(239, 239, 239);">Hallo an alle,</span>
 
<span style="color: rgb(51, 51, 51); font-family: Tahoma, Verdana, Arial, sans-serif; font-size: 14px; background-color: rgb(239, 239, 239);">habe eine Userform mit folgendem Code:</span>
 
Private Sub ListBox1_Click()
 Dim pfadPDF As String
 Dim lZeile As Long
  
   'Wenn der Benutzer einen Namen anklickt, suchen wir
   'diesen in der Tabelle6 heraus und tragen die Daten
   'in die TextBoxen ein.
    
   'Wir löschen standardmäßig alle bisherigen TextBoxen-Inhalte
   TextBox1 = ""
   TextBox2 = ""
   TextBox3 = ""
   TextBox4 = ""
   TextBox5 = ""
   TextBox6 = ""
   TextBox7 = ""
   TextBox8 = ""
    
   'Nur wenn ein Eintrag selektiert/markiert ist
   'If ListBox1.ListIndex >= 0 Then
    
       lZeile = 2 'Start in Zeile 2, Zeile 1 sind ja die Überschriftrn
       'Schleife solange etwas in der ersten Spalte in Tabelle 6 drin steht
       Do While Trim(CStr(Tabelle6.Cells(lZeile, 2).Value)) <> ""
        
           'Wenn wir den Namen aus der ListBox1 in der Tabelle 6 Spalte 1
           'gefunden haben, übertragen wir die anderen Spalteninhalte
           'in die TextBoxen!
           If ListBox1.Text = Trim(CStr(Tabelle6.Cells(lZeile, 2).Value)) Then
            
               'TextBoxen füllen
               TextBox1 = Trim(CStr(Tabelle6.Cells(lZeile, 1).Value))
               TextBox2 = "Nr_" & Tabelle6.Cells(lZeile, 2).Value
               TextBox3 = Tabelle6.Cells(lZeile, 3).Value
               TextBox4 = Tabelle6.Cells(lZeile, 4).Value
               TextBox5 = Tabelle6.Cells(lZeile, 5).Value
               TextBox6 = Tabelle6.Cells(lZeile, 6).Value
               TextBox7 = Format(Tabelle6.Cells(lZeile, 7).Value, "Currency")
               TextBox7.BackColor = Tabelle6.Cells(lZeile, 12).DisplayFormat.Interior.Color
               TextBox8 = Tabelle6.Cells(lZeile, 9).Value
                            
               Exit Do 'Vorzeitiges Ende, da der Datensatz schon gefunden ist
            
           End If
        
           lZeile = lZeile + 1 'Nächste Zeile bearbeiten
        
       Loop
        
       pfadPDF = Worksheets("Konfiguration").Range("C3").Value
       Dim MyObj As Object, MySource As Object, file As Variant
       file = Dir(pfadPDF)
       While (file <> "")
       If InStr(file, UserForm2.TextBox2) Then
       UserForm2.TextBox9.Value = pfadPDF & file
       Exit Sub
       End If
       file = Dir
 Wend
    
End Sub
 
Code:
 
Private Sub UserForm_Initialize()
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;"> </span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;"Dim lZeile As Long</span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;"> </span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">   'Alle TextBoxen leer machen</span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">   TextBox1 = ""</span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">   TextBox2 = ""</span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">   TextBox3 = ""</span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">   TextBox4 = ""</span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">   TextBox5 = ""</span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">   TextBox6 = ""</span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">   TextBox7 = ""</span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">   TextBox8 = ""</span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;"> </span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">   'In dieser Routine laden wir alle vorhandenen</span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">   'Einträge in die ListBox1</span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">   ListBox1.Clear 'Zuerst einmal die Liste leeren</span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">       </span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">   lZeile = 2 'Start in Zeile 2, Zeile 1 sind ja die Überschriftrn</span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">   'Schleife solange etwas in der ersten Spalte in Tabelle 1 drin steht</span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">   Do While Trim(CStr(Tabelle6.Cells(lZeile, 2).Value)) <> ""</span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">       </span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">       'Aktuelle Zeile in die ListBox eintragen</span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">       'ListBox1.AddItem "Rechnung Nr. " & Trim(CStr(Tabelle6.Cells(lZeile, 2).Value) & " vom " & Trim(CStr(Tabelle6.Cells(lZeile, 1).Value)) & " - " & Trim(CStr(Tabelle6.Cells(lZeile, 4).Value)))</span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">       ListBox1.AddItem Trim(CStr(Tabelle6.Cells(lZeile, 2).Value))</span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">       lZeile = lZeile + 1 'Nächste Zeile bearbeiten</span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">       </span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">   Loop</span>
<span style="color: rgb(51, 51, 51); font-family: Monaco, Consolas, Courier, monospace; font-size: 13px;">End Sub
 
</span>Funktioniert soweit recht gut, nur möchte ich in der Listbox1 nicht alle Einträge von Spalte 1 haben, sondern sie an ein Bedingung knüpfn, z.B., wenn Tabelle6.Cells(lZeile, 11).Value = "" oder wenn Tabelle6.Cells(lZeile, 12).Value ist rot markiert.

Bin für jede Hilfe dankbar


Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
Rot Listbox um Funktion erweitern
06.09.2017 17:33:12 Hatsch
NotSolved
07.09.2017 16:06:46 Mackie
NotSolved