Barnardos1
New Member
- Joined
- Nov 24, 2015
- Messages
- 3
Hey guys, I have a query based on visual basic coding in Excel. I am creating a user form for a piece of work, and there is a certain bit of the coding I am having an issue with. Here is my coding so far below:
Private Sub cmdAdd_Click()
'Copy input values to sheet.
Dim lRow As Long
Dim Row As Worksheet
If txtSupplierno.TextLength = 5 And IsNumeric(txtSupplierno.Value) Then
Set ws = Worksheets("Userform")
lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
With ws
.Cells(lRow, 1).Value = Me.txtName.Value
.Cells(lRow, 2).Value = Me.cboDepartment.Value
.Cells(lRow, 3).Value = Me.txtSupplierno.Value
.Cells(lRow, 4).Value = Me.txtEmployeeno.Value
.Cells(lRow, 5).Value = Me.txtDate.Value
.Cells(lRow, 6).Value = Me.cboCompany.Value
.Cells(lRow, 7).Value = Me.txtCostcentre.Value
.Cells(lRow, 8).Value = Me.txtAccount.Value
.Cells(lRow, 9).Value = Me.txtGroup.Value
.Cells(lRow, 10).Value = Me.txtClass.Value
.Cells(lRow, 11).Value = Me.txtProduct.Value
.Cells(lRow, 12).Value = Me.txtSpare.Value
.Cells(lRow, 13).Value = Me.txtAmntexclvat.Value
.Cells(lRow, 14).Value = Me.cbovatrate.Value
.Cells(lRow, 15).Value = Me.cboValid.Value
End With
Else
MsgBox "Enter a 5 digit supplier number!"
txtSupplierno.Value = ""
End If
End Sub
For my user form I am adding some fields which I would like to be mandatory so there needs to be coding to validate this. So far only my "txtSupplierno" is working but when I try to add my other fields using the If statement it doesn’t seem to work. I want it to work so that if someone enters a Cost Centre with less than 5 numbers, it will not still save. So far I have done it to work with Supplierno but I just need it to work for others with the If statement. If anyone knows how to solve this issue it would be very helpful. Thanks!
Private Sub cmdAdd_Click()
'Copy input values to sheet.
Dim lRow As Long
Dim Row As Worksheet
If txtSupplierno.TextLength = 5 And IsNumeric(txtSupplierno.Value) Then
Set ws = Worksheets("Userform")
lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
With ws
.Cells(lRow, 1).Value = Me.txtName.Value
.Cells(lRow, 2).Value = Me.cboDepartment.Value
.Cells(lRow, 3).Value = Me.txtSupplierno.Value
.Cells(lRow, 4).Value = Me.txtEmployeeno.Value
.Cells(lRow, 5).Value = Me.txtDate.Value
.Cells(lRow, 6).Value = Me.cboCompany.Value
.Cells(lRow, 7).Value = Me.txtCostcentre.Value
.Cells(lRow, 8).Value = Me.txtAccount.Value
.Cells(lRow, 9).Value = Me.txtGroup.Value
.Cells(lRow, 10).Value = Me.txtClass.Value
.Cells(lRow, 11).Value = Me.txtProduct.Value
.Cells(lRow, 12).Value = Me.txtSpare.Value
.Cells(lRow, 13).Value = Me.txtAmntexclvat.Value
.Cells(lRow, 14).Value = Me.cbovatrate.Value
.Cells(lRow, 15).Value = Me.cboValid.Value
End With
Else
MsgBox "Enter a 5 digit supplier number!"
txtSupplierno.Value = ""
End If
End Sub
For my user form I am adding some fields which I would like to be mandatory so there needs to be coding to validate this. So far only my "txtSupplierno" is working but when I try to add my other fields using the If statement it doesn’t seem to work. I want it to work so that if someone enters a Cost Centre with less than 5 numbers, it will not still save. So far I have done it to work with Supplierno but I just need it to work for others with the If statement. If anyone knows how to solve this issue it would be very helpful. Thanks!