Option
Explicit
Option
Compare Text
Private
Sub
CommandButton1_Click()
Dim
lSpalte
As
Long
lSpalte = 2
Do
While
Trim(
CStr
(Tabelle2.Cells(1, lSpalte).Value)) <>
""
lSpalte = lSpalte + 1
Loop
Tabelle2.Cells(1, lSpalte) =
CStr
(
"Neuer Eintrag Spalte "
& lSpalte)
ListBox1.AddItem
CStr
(
"Neuer Eintrag Spalte "
& lSpalte)
ListBox1.ListIndex = ListBox1.ListCount - 1
End
Sub
Private
Sub
CommandButton2_Click()
Dim
lSpalte
As
Long
If
ListBox1.ListIndex = -1
Then
Exit
Sub
lSpalte = 2
Do
While
Trim(
CStr
(Tabelle2.Cells(1, lSpalte).Value)) <>
""
If
ListBox1.Text = Trim(
CStr
(Tabelle2.Cells(1, lSpalte).Value))
Then
Tabelle2.Columns(lSpalte).Delete
Call
UserForm_Initialize
If
ListBox1.ListCount > 0
Then
ListBox1.ListIndex = 0
Exit
Do
End
If
lSpalte = lSpalte + 1
Loop
End
Sub
Private
Sub
CommandButton3_Click()
Dim
lSpalte
As
Long
If
ListBox1.ListIndex = -1
Then
Exit
Sub
If
Trim(
CStr
(TextBox1.Text)) =
""
Then
MsgBox
"Sie müssen mindestens einen Namen eingeben!"
, vbCritical + vbOKOnly,
"FEHLER!"
Exit
Sub
End
If
lSpalte = 2
Do
While
Trim(
CStr
(Tabelle2.Cells(1, lSpalte).Value)) <>
""
If
ListBox1.Text = Trim(
CStr
(Tabelle2.Cells(1, lSpalte).Value))
Then
Tabelle2.Cells(1, lSpalte).Value = Trim(
CStr
(TextBox1.Text))
Tabelle2.Cells(2, lSpalte).Value = TextBox2.Text
Tabelle2.Cells(3, lSpalte).Value = TextBox3.Text
Tabelle2.Cells(4, lSpalte).Value = TextBox4.Text
Tabelle2.Cells(5, lSpalte).Value = TextBox5.Text
Tabelle2.Cells(6, lSpalte).Value = TextBox6.Text
If
ListBox1.Text <> Trim(
CStr
(TextBox1.Text))
Then
Call
UserForm_Initialize
If
ListBox1.ListCount > 0
Then
ListBox1.ListIndex = 0
End
If
Exit
Do
End
If
lSpalte = lSpalte + 1
Loop
End
Sub
Private
Sub
CommandButton4_Click()
Unload
Me
End
Sub
Private
Sub
ListBox1_Click()
Dim
lSpalte
As
Long
TextBox1 =
""
TextBox2 =
""
TextBox3 =
""
TextBox4 =
""
TextBox5 =
""
TextBox6 =
""
If
ListBox1.ListIndex >= 0
Then
lSpalte = 2
Do
While
Trim(
CStr
(Tabelle2.Cells(1, lSpalte).Value)) <>
""
If
ListBox1.Text = Trim(
CStr
(Tabelle2.Cells(1, lSpalte).Value))
Then
TextBox1 = Trim(
CStr
(Tabelle2.Cells(1, lSpalte).Value))
TextBox2 = Tabelle2.Cells(2, lSpalte).Value
TextBox3 = Tabelle2.Cells(3, lSpalte).Value
TextBox4 = Tabelle2.Cells(4, lSpalte).Value
TextBox5 = Tabelle2.Cells(5, lSpalte).Value
TextBox6 = Tabelle2.Cells(6, lSpalte).Value
Exit
Do
End
If
lSpalte = lSpalte + 1
Loop
End
If
End
Sub
Private
Sub
UserForm_Activate()
If
ListBox1.ListCount > 0
Then
ListBox1.ListIndex = 0
End
Sub
Private
Sub
UserForm_Initialize()
Dim
lSpalte
As
Long
TextBox1 =
""
TextBox2 =
""
TextBox3 =
""
TextBox4 =
""
TextBox5 =
""
TextBox6 =
""
ListBox1.Clear
lSpalte = 2
Do
While
Trim(
CStr
(Tabelle2.Cells(1, lSpalte).Value)) <>
""
ListBox1.AddItem Trim(
CStr
(Tabelle2.Cells(1, lSpalte).Value))
lSpalte = lSpalte + 1
Loop
End
Sub