I am trying to Add new record through User Input form via Vba But I am getting Runtime Error 1004 runtime error 1004 vba application defined or object defined error. Can Someone Pls help. Please find my Code below
Private Sub CommandButton1_Click()
Sheet7.Activate
Range("a1").End(x1Down).Offset(1, 0).Value = Range("a1").End(x1Down).Value 1
Range("b1").End(x1Down).Offset(1, 0).Value = TextBox27.Value
Range("c1").End(x1Down).Offset(1, 0).Value = ComboBox8.Value
Range("d1").End(x1Down).Offset(1, 0).Value = ComboBox3.Value
Range("e1").End(x1Down).Offset(1, 0).Value = TextBox50.Value
Range("f1").End(x1Down).Offset(1, 0).Value = ComboBox1.Value
Range("g1").End(x1Down).Offset(1, 0).Value = TextBox48.Value
Range("h1").End(x1Down).Offset(1, 0).Value = TextBox47.Value
Range("i1").End(x1Down).Offset(1, 0).Value = TextBox46.Value
Range("j1").End(x1Down).Offset(1, 0).Value = ComboBox7.Value
Range("k1").End(x1Down).Offset(1, 0).Value = TextBox44.Value
Range("l1").End(x1Down).Offset(1, 0).Value = TextBox43.Value
Range("m1").End(x1Down).Offset(1, 0).Value = TextBox42.Value
Range("n1").End(x1Down).Offset(1, 0).Value = TextBox41.Value
Range("o1").End(x1Down).Offset(1, 0).Value = TextBox40.Value
Range("p1").End(x1Down).Offset(1, 0).Value = TextBox39.Value
Range("q1").End(x1Down).Offset(1, 0).Value = TextBox38.Value
Range("r1").End(x1Down).Offset(1, 0).Value = TextBox37.Value
Range("s1").End(x1Down).Offset(1, 0).Value = TextBox36.Value
Range("t1").End(x1Down).Offset(1, 0).Value = TextBox35.Value
Range("u1").End(x1Down).Offset(1, 0).Value = TextBox34.Value
Range("v1").End(x1Down).Offset(1, 0).Value = TextBox28.Value
Range("w1").End(x1Down).Offset(1, 0).Value = TextBox32.Value
Range("x1").End(x1Down).Offset(1, 0).Value = TextBox31.Value
CodePudding user response:
You should only be using End()
once, on a column guaranteed to always have a value: if you use End()
for each value then your data could end up on different rows.
Eg:
Private Sub CommandButton1_Click()
Dim rw As Range
'Find the next empty row
Set rw = Sheet7.Cells(rows.count, "A").end(xlUp).offset(1).EntireRow
'Add the form date
With rw
.Columns(1).value = .Columns(1).Offset(-1).value 1
.Columns(2).value = TextBox27.Value
.Columns(3).value = ComboBox8.Value
.Columns(4).value = ComboBox3.Value
'etc etc
End with