habe einen Userform, die eingaben von 5 Textboxen sollen in die Range "G3:G7" kommen, falls dort schon werte drinnen stehen soll sich die "x" Variable (x ist die Anzahl der Zeilen) verändern.
"x" soll dann die letzte beschriebene Zeile + 3 sein.
Ich bekomme bei meinem Code allerdings immer einen Objekt definierten Fehler.
Hier mein kompletter Code:
Sub B1_Daten()
'On Error GoTo B1_Daten_Error
bool = True
For i = 1 To 5
tbv(i) = UserForm1.Controls("TextBox" & i).Value
If tbv(i) = "" Then
tbv(i) = "0"
End If
arrDaten(i) = tbv(i)
Next i
Set wks = ThisWorkbook.Sheets("Daten")
With wks
x = 3
y = 7
Set rngBereich = .Range(.Cells(x, y), .Cells(x + 4, y))
blanks = 0
For Each c In rngBereich
If c.Value = "" Then
blanks = blanks + 1
End If
Next c
If blanks > 0 Then
bool = False
End If
If bool = True Then
x = .Range(.Cells(.Rows.Count, y), .Cells(3, y)).Find(What:="*", LookIn:=xlValues, _
_
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Rows
x = x + 3
End If
If bool = False Then
.Cells(x, y).Value = arrDaten(1)
.Cells(x + 1, y).Value = arrDaten(2)
.Cells(x + 2, y).Value = arrDaten(3)
.Cells(x + 3, y).Value = arrDaten(4)
.Cells(x + 4, y).Value = arrDaten(5)
Else
.Cells(x, y).Value = arrDaten(1)
.Cells(x + 1, y).Value = arrDaten(2)
.Cells(x + 2, y).Value = arrDaten(3)
.Cells(x + 3, y).Value = arrDaten(4)
.Cells(x + 4, y).Value = arrDaten(5)
End If
End With
'On Error GoTo 0
Exit Sub
B1_Daten_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure B1_Daten of Sub _
Modul2"
End Sub
Variablen (evtl. nicht alle in Verwendung):
Option Explicit
Dim i
Dim n As Integer
Dim x, y, blanks As Long
Dim wks As Worksheet
Dim wkb As Workbook
Dim lngZeile, lngSpalte As Long
Dim c, rngBereich As Range
Dim arrDaten(1 To 5) As String
Dim cb1, cb2, tb86
Dim txtb As Control
Dim tbv(1 To 5)
Dim bool As Boolean
Solltet ihr eine Testdatei mit Code brauchen, sagt bescheid, ich stelle sie dann rein :)