Using Visual Basic in Excel

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!
 

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