My userform works fine to fill in the fields on an excel spreadsheet, but it refuses to move to the next line. I can't do it by asking to find an empty row either, because columns A and C are prefilled. Is there a way to make the userform jump to the next line once it has been complete and submitted and the fields are filled out, maybe by using the B column as a way to know whether the row is open to use? Because no matter what, the A and C columns are filled. Also, once the user is done, saves the document, and comes back to it later, will the userform pick up on whatever line it last left off on? I know i posted this already, but no solutions have worked and I figured I would add more detail. Sorry if some of this seems novice, I am new to VBA. Thank you!
Private Sub butOK_Click()
Dim RowCount As Long
Dim ctl As Control
RowCount = Worksheets("EXPECTED RETURNS").Range("A6865").CurrentRegion.Rows.Count
With Worksheets("EXPECTED RETURNS").Range("A6865")
.Offset(LastRow, 1).Value = Me.txtDate.Value
.Offset(LastRow, 3).Value = Me.txtDevice.Value
.Offset(LastRow, 4).Value = Me.txtID.Value
.Offset(LastRow, 5).Value = Me.txtSN.Value
.Offset(LastRow, 6).Value = Me.txtTrans.Value
.Offset(LastRow, 7).Value = Me.txtIDTrans.Value
.Offset(LastRow, 8).Value = Me.txtMS.Value
.Offset(LastRow, 9).Value = Me.txtCountry.Value
.Offset(LastRow, 10).Value = Me.txtCamp.Value
.Offset(LastRow, 11).Value = Me.txtOrig.Value
.Offset(LastRow, 12).Value = Me.txtProgram.Value
.Offset(LastRow, 13).Value = Me.txtPOC.Value
.Offset(LastRow, 14).Value = Me.txtPOCEmail.Value
.Offset(LastRow, 15).Value = Me.txtDSN.Value
.Offset(LastRow, 16).Value = Me.txtIR.Value
.Offset(LastRow, 17).Value = Me.txtEI.Value
End With
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
ctl.Value = ""
ElseIf TypeName(ctl) = "CheckBox" Then
ctl.Value = False
End If
Next ctl
End Sub
The code below will find the last used row in
EXPECTED RETURNS
sheet and copy data in next row. Also, it assumes that you set atag
number to all your relevant elements in the form: 1 forTextDate
, 3 forTextDevice
and so on. This way, your code can be reduce to something like the following:Try this instead...
You can add na iff statement to have a positive result and a negative result if you want