Microsoft Office Forum [ www.Office-Fragen.de ] >> READONLY <<

Microsoft Office 2003-2019 => Excel => Thema gestartet von: tooob am August 19, 2015, 12:08:17 Nachmittag

Titel: Daten in Tabelle per Userform ändern
Beitrag von: tooob am August 19, 2015, 12:08:17 Nachmittag
Hallo zusammen,

ich versuche Daten aus einer Tabelle zu suchen (nach Namen), und dann Änderungen abzuspeichern. Das Suchen mittels des Buttons Such funktioniert einwandfrei.
Der Button speichern funktioniert hingegen nicht. Er schreibt eine neue Zeile statt die alte zu überspeichern (Ist bei dem Code auch zu erwarten, aber ich weiß nicht wie man emptyRow die richtige Zelle zu weißt).
Wie kann ich der Variabel emptyRow die richtige Zeile zuweisen, damit er auch darin überschreibt ?


Hier der Code zum Speicher Button:

Private Sub Speichern_Click()

Dim emptyRow as Long

Worksheets("Daten").Activate


emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1

Cells(emptyRow, 1).Value = TextBox2.Value
Cells(emptyRow, 2).Value = TextBox3.Value
Cells(emptyRow, 3).Value = TextBox4.Value
Cells(emptyRow, 4).Value = TextBox5.Value
Cells(emptyRow, 5).Value = TextBox6.Value
Cells(emptyRow, 6).Value = ComboBox1.Value


Cells(emptyRow, 7).Value = TextBox8.Value

Cells(emptyRow, 8).Value = ComboBox2.Value
Cells(emptyRow, 9).Value = ComboBox3.Value



Cells(emptyRow, 10).Value = TextBox10.Value


If CheckBox1.Value = True Then Cells(emptyRow, 11).Value = CheckBox1.Caption
If CheckBox2.Value = True Then Cells(emptyRow, 11).Value = CheckBox2.Caption


Cells(emptyRow, 12).Value = ComboBox4.Value
Cells(emptyRow, 13).Value = ComboBox5.Value
Cells(emptyRow, 14).Value = ComboBox6.Value
Cells(emptyRow, 15).Value = ComboBox7.Value

Cells(emptyRow, 19).Value = TextBox9.Value
Cells(emptyRow, 20).Value = TextBox11.Value
Cells(emptyRow, 21).Value = TextBox12.Value
Cells(emptyRow, 22).Value = TextBox13.Value

If CheckBox3.Value = True Then Cells(emptyRow, 17).Value = CheckBox3.Caption
If CheckBox4.Value = True Then Cells(emptyRow, 17).Value = CheckBox4.Caption

If CheckBox5.Value = True Then Cells(emptyRow, 18).Value = CheckBox7.Caption
If CheckBox6.Value = True Then Cells(emptyRow, 18).Value = CheckBox8.Caption

If CheckBox7.Value = True Then Cells(emptyRow, 16).Value = CheckBox7.Caption
If CheckBox8.Value = True Then Cells(emptyRow, 16).Value = CheckBox8.Caption


End Sub


Hier ein Teil des Codes zum Suchen:

Private Sub Such_Click()

 Dim rZelle        As Range
 Dim sSuchbegriff  As String

    If Trim$(TextBox1.Value) <> "" Then
       sSuchbegriff = Trim$(TextBox1.Value)
     Else
       MsgBox "Sie müssen einen Suchbegiff eingeben - danke.", _
          48, "   Hinweis für " & Application.UserName
       Exit Sub
    End If

    With ThisWorkbook.Worksheets("Daten").Columns(1)
       Set rZelle = .Find(What:=sSuchbegriff, LookAt:=xlWhole, LookIn:=xlValues)
       If Not rZelle Is Nothing Then
         TextBox2.Value = .Range("A" & rZelle.Row).Value
          TextBox3.Value = .Range("B" & rZelle.Row).Value
          TextBox4.Value = .Range("C" & rZelle.Row).Value
....
usw.



Vielen Dank!!!

Titel: Antw: Daten in Tabelle per Userform ändern
Beitrag von: tooob am August 19, 2015, 12:39:15 Nachmittag
Hab es schon!
Trotzdem Danke