AW: .Text in Array schreiben
02.04.2010 10:48:52
Fatih
Lieber Erich,
vielen Dank für dein Tipp, kann ich denn Code jetzt einfach in meine Datei reinkopieren?
sorry bin eigentlich noch ein Anfänger im VBA Bereich :-( ich weiss jetzt nicht wie ich vorgehen soll.
In den letzten Tagen habe ich sehr lehrreiche informationen bzw. Hilfestellung bekommen, insbesondere von Chris,fsc,Hayo.
Die wichtigsten Texboxen sind die 6 & 7 auf den anderen werden nur Texte ausgelesen.
Hier der gesamte Code für meine AusleseUserform:
Option Explicit
Public ListInd As Long, bol As Boolean
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()
Dim i As Long
ListInd = ListBox1.ListIndex
bol = True
With Sheets("Daten")
.Cells(ListBox1.ListIndex + 2, 1) = TextBox1
.Cells(ListBox1.ListIndex + 2, 2) = TextBox4
.Cells(ListBox1.ListIndex + 2, 3) = TextBox2
.Cells(ListBox1.ListIndex + 2, 4) = TextBox3
.Cells(ListBox1.ListIndex + 2, 5) = TextBox5
.Cells(ListBox1.ListIndex + 2, 6) = CDbl(TextBox6.Text)
.Cells(ListBox1.ListIndex + 2, 7) = CDbl(TextBox7.Text)
.Cells(ListBox1.ListIndex + 2, 8) = TextBox8
.Cells(ListBox1.ListIndex + 2, 9) = TextBox9
.Cells(ListBox1.ListIndex + 2, 10) = TextBox10
End With
For i = 1 To 10
Me.Controls("TextBox" & i) = ""
Next i
ListBox1.Clear
Call t
ListBox1.ListIndex = ListInd
With ListBox1
TextBox1 = .List(.ListIndex, 0)
TextBox2 = .List(.ListIndex, 2)
TextBox3 = .List(.ListIndex, 3)
TextBox4 = .List(.ListIndex, 1)
TextBox5 = .List(.ListIndex, 4)
TextBox6 = .List(.ListIndex, 5)
TextBox7 = .List(.ListIndex, 6)
TextBox8 = .List(.ListIndex, 7)
TextBox9 = .List(.ListIndex, 8)
TextBox10 = .List(.ListIndex, 9)
End With
MsgBox "Daten wurden korrigiert!"
End Sub
Private Sub CommandButton4_Click()
Dim i As Long
If ListBox1.ListIndex = 0 Then MsgBox ("1.Datensatz wird angezeigt") Else ListBox1.ListIndex = _
ListBox1.ListIndex - 1
End Sub
Private Sub CommandButton3_Click()
Dim i As Long
If ListBox1.ListIndex = ListBox1.ListCount - 1 Then MsgBox ("kein weiterer Datensatz") Else _
ListBox1.ListIndex = ListBox1.ListIndex + 1
End Sub
Private Sub ListBox1_Change()
Dim i As Long
If bol Then bol = False: Exit Sub
For i = 1 To 10
Me.Controls("TextBox" & i) = ""
Next i
With ListBox1
TextBox1 = .List(.ListIndex, 0)
TextBox2 = .List(.ListIndex, 2)
TextBox3 = .List(.ListIndex, 3)
TextBox4 = .List(.ListIndex, 1)
TextBox5 = .List(.ListIndex, 4)
TextBox6 = .List(.ListIndex, 5)
TextBox7 = .List(.ListIndex, 6)
TextBox8 = .List(.ListIndex, 7)
TextBox9 = .List(.ListIndex, 8)
TextBox10 = .List(.ListIndex, 9)
End With
End Sub
Private Sub UserForm_Initialize()
Dim i As Long, DatArr As Variant, j As Long
With Sheets("Daten")
If .Cells(Rows.Count, 1).End(xlUp).Row > 1 Then
DatArr = .Range("A2:J" & .Cells(Rows.Count, 1).End(xlUp).Row)
ListBox1.List = DatArr
ListBox1.ListIndex = 0
End If
End With
With ListBox1
.ColumnCount = 10
TextBox1 = .List(.ListIndex, 0)
TextBox2 = .List(.ListIndex, 2)
TextBox3 = .List(.ListIndex, 3)
TextBox4 = .List(.ListIndex, 1)
TextBox5 = .List(.ListIndex, 4)
TextBox6 = .List(.ListIndex, 5)
TextBox7 = .List(.ListIndex, 6)
TextBox8 = .List(.ListIndex, 7)
TextBox9 = .List(.ListIndex, 8)
TextBox10 = .List(.ListIndex, 9)
End With
End Sub
Sub t()
Dim DatArr As Variant
With Sheets("Daten")
If .Cells(Rows.Count, 1).End(xlUp).Row > 1 Then
DatArr = .Range("A2:J" & .Cells(Rows.Count, 1).End(xlUp).Row)
ListBox1.List = DatArr
ListBox1.ListIndex = 0
End If
End With
End Sub
Vielen Dank für deine Hilfe Erich
lg
fatih