Data from a userform transferring to the same row in Excel.

VIPERMAN1

New Member
Joined
Dec 6, 2011
Messages
10
HI, i have so far put together the below code for an "OK" command button

When i do click OK, the data is transferred to the same cell (A75) as the last entry, but i would like it to go in the next row available, in this case A76.

Am i supposed to be looking at an Offset rule in the part of the code that writes the data to worksheet (which i have put in bold below).

Any guidance would be appreciated.

Private Sub cmdOK_Click()


Dim RowCount As Long
Dim ctl As Control
'Check user input
If Me.TxttFirstName.Value = "" Then
MsgBox "Please enter a First Name.", vbExclamation, "Season Ticket"
Me.TxttFirstName.SetFocus
Exit Sub
End If

If Me.TxttSurname.Value = "" Then
MsgBox "Please enter a Surname.", vbExclamation, "Season Ticket"
Me.TxttSurname.SetFocus
Exit Sub
End If

If Me.TxttDoB.Value = "" Then
MsgBox "Please enter a Date Of Birth.", vbExclamation, "Season Ticket"
Me.TxttDoB.SetFocus
Exit Sub
End If

If Me.TxttAddress1.Value = "" Then
MsgBox "Please enter an Address.", vbExclamation, "Season Ticket"
Me.TxttAddress1.SetFocus
Exit Sub
End If

If Me.TxttTown.Value = "" Then
MsgBox "Please enter a Town.", vbExclamation, "Season Ticket"
Me.TxttTown.SetFocus
Exit Sub
End If

If Me.TxttCountry.Value = "" Then
MsgBox "Please enter a Country.", vbExclamation, "Season Ticket"
Me.TxttCountry.SetFocus
Exit Sub
End If

If Me.txttPostcode.Value = "" Then
MsgBox "Please enter a Postcode.", vbExclamation, "Season Ticket"
Me.txttPostcode.SetFocus
Exit Sub
End If

If Me.TxttEmail.Value = "" Then
MsgBox "Please enter an Email Address.", vbExclamation, "Season Ticket"
Me.TxttEmail.SetFocus
Exit Sub
End If

If Me.txttTelephone.Value = "" Then
MsgBox "Please enter a Telephone Number.", vbExclamation, "Season Ticket"
Me.txttTelephone.SetFocus
Exit Sub
End If

If Me.CmbooTicketType.Value = "" Then
MsgBox "Please select a Ticket Type.", vbExclamation, "Season Ticket"
Me.CmbooTicketType.SetFocus
Exit Sub
End If

If Me.TxttDateOfApplication.Value = "" Then
MsgBox "Please enter the date the application was received.", vbExclamation, "Season Ticket"
Me.TxttDateOfApplication.<wbr>SetFocus
Exit Sub
End If

If Me.CmbooRequestedSeat.Value = "" Then
MsgBox "Please select a Seat.", vbExclamation, "Season Ticket"
Me.CmbooRequestedSeat.<wbr>SetFocus
Exit Sub
End If

If Not IsNumeric(Me.txttTelephone.<wbr>Value) Then
MsgBox "The Telephone box must contain a number.", vbExclamation, "Season Ticket"
Me.txttTelephone.SetFocus
Exit Sub
End If


If Not IsDate(Me.TxttDoB.Value) Then
MsgBox "The Date Of Birth box must contain a date.", vbExclamation, "Season Ticket"
Me.TxttDoB.SetFocus
Exit Sub
End If


If Not IsDate(Me.<wbr>TxttDateOfApplication.Value) Then
MsgBox "The Date Of Application Received box must contain a date.", vbExclamation, "Season Ticket"
Me.TxttDateOfApplication.<wbr>SetFocus
Exit Sub
End If
'Write data to worksheet
RowCount = Worksheets("Ticket Holder Details").Range("A75").<wbr>CurrentRegion.Rows.Count
With Worksheets("Ticket Holder Details").Range("A75")

.Offset(RowCount, 3).Value = Me.TxttFirstName.Value
.Offset(RowCount, 4).Value = Me.TxttSurname.Value
.Offset(RowCount, 5).Value = DateValue(Me.TxttDoB.Value)
.Offset(RowCount, 6).Value = Me.TxttAddress1.Value
.Offset(RowCount, 7).Value = Me.TxttAddress2.Value
.Offset(RowCount, 8).Value = Me.TxttTown.Value
.Offset(RowCount, 9).Value = Me.TxttCountry.Value
.Offset(RowCount, 10).Value = Me.txttPostcode.Value
.Offset(RowCount, 11).Value = Me.TxttEmail.Value
.Offset(RowCount, 12).Value = Me.txttTelephone.Value
.Offset(RowCount, 13).Value = Me.CmbooTicketType.Value
.Offset(RowCount, 14).Value = DateValue(Me.<wbr>TxttDateOfApplication.Value)
.Offset(RowCount, 17).Value = Me.CmbooRequestedSeat.Value

If Me.ChkkAgeCheck.Value = True Then
.Offset(RowCount, 19).Value = "Yes"
Else
.Offset(RowCount, 19).Value = "No"
End If
.Offset(RowCount, 20).Value = Format(Now, "dd/mm/yyyy")

End With




' Clear the form
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
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
When I run this the data is going 75 rows down from A75 because you are starting from cell A75 for your offset.
Code:
[FONT=arial]RowCount = Worksheets("Ticket Holder Details").Range("A75").<wbr>CurrentRegion.Rows.Count[/FONT]
[FONT=arial]With Worksheets("Ticket Holder Details").Range("A75")[/FONT]

[FONT=arial] .Offset(RowCount, 3).Value = Me.TxttFirstName.Value[/FONT]

Assuming that there is data in the sheet so that the excel gets the current region right then this would work but not sure why you would use A75 to get the current region.
Code:
RowCount = Worksheets("[FONT=Arial]Ticket Holder Details[/FONT]").Range("A75").CurrentRegion.Rows.Count
With Worksheets("[FONT=Arial]Ticket Holder Details[/FONT]").Range("A2")
 [FONT=Arial].Offset(RowCount, 3).Value = Me.TxttFirstName.Value[/FONT]
End With
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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