next empty row

ashukla1

New Member
Joined
Oct 31, 2017
Messages
7
I have created a userform and i am able get the form to transfer data in the sheet i require.
however i am unable to move to the next row once i've used the first row

I have 4 text boxes 1 Combobox and 1 list box

Please help me as i am very new to VBA and cant seem to get this right.

Below is my Code


VBA Code:
Private Sub cmdExit_Click()

Unload Me

End Sub
Private Sub CMDsubmit_Click()
Sheet2.Activate
Range("a2").Value = TextBox1.Value
Range("b2").Value = CBcollector.Value
Range("c2").Value = ListBox1.Value
Range("d2").Value = TextBox3.Value
Range("E2").Value = TextBox2.Value
End Sub

Private Sub CommandButton1_Click()
Dim z As Control
For Each z In UserForm1.Controls
If TypeName(z) = "TextBox" Then
z.Value = ""
End If
Next z
End Sub


Private Sub TextBox1_AfterUpdate()
If IsDate(Me.TextBox1.Text) Then
Me.TextBox1.Text = Format(Me.TextBox1.Text, "dd/mm/yyyy")
End If
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi,
try this change to your code

VBA Code:
Private Sub CMDsubmit_Click()
    Dim Nextrow As Long
    With Sheet2
    Nextrow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
        .Cells(Nextrow, 1).Value = TextBox1.Value
        .Cells(Nextrow, 2).Value = CBcollector.Value
        .Cells(Nextrow, 3).Value = ListBox1.Value
        .Cells(Nextrow, 4).Value = TextBox3.Value
        .Cells(Nextrow, 5).Value = TextBox2.Value
    End With
End Sub

Dave
 
Upvote 0
Try this:
VBA Code:
Private Sub CMDsubmit_Click()
Dim r as Long
Sheet2.Activate
'Find next blank row
r = Cells(Rows.Count, "A").End(xlUp).Row + 1
Range("A" & r).Value = TextBox1.Value
Range("B" & r).Value = CBcollector.Value
Range("C" & r).Value = ListBox1.Value
Range("D" & r).Value = TextBox3.Value
Range("E" & r).Value = TextBox2.Value
End Sub
 
Upvote 0
How about
VBA Code:
Private Sub CMDsubmit_Click()
   With Sheet2.Range("A" & Rows.Count).End(xlUp)
      .Offset(1).Value = TextBox1.Value
      .Offset(1, 1).Value = CBcollector.Value
      .Offset(1, 2).Value = ListBox1.Value
      .Offset(1, 3).Value = TextBox3.Value
      .Offset(1, 4).Value = TextBox2.Value
   End With
End Sub
 
Upvote 0
thanks Guys this worked like a charm...

just one more thing

what code should i add to it if i wish to insert a message box when i hit submit
 
Upvote 0
Maybe
VBA Code:
Private Sub CMDsubmit_Click()
   With Sheet2.Range("A" & Rows.Count).End(xlUp)
      .Offset(1).Value = TextBox1.Value
      .Offset(1, 1).Value = CBcollector.Value
      .Offset(1, 2).Value = ListBox1.Value
      .Offset(1, 3).Value = TextBox3.Value
      .Offset(1, 4).Value = TextBox2.Value
   End With
   MsgBox "Done"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,968
Messages
6,122,509
Members
449,089
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top