ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,699
- Office Version
- 2007
- Platform
- Windows
I have a userform where i enter data then when i press the Click To Transfer button this data is then entered on my worksheet.
I would like a code so upon pressing Click To Transfer it should check first that the customers name does not exist.
If the name does not exist then let the data be saved on the sheet.
Should there be a customers name of which is the same then i need to see a msgbox advising me of this.
Some info for you.
Worksheet is called POSTAGE
Customers name on worksheet will always be in column B
Range on worksheet is B8 & onwards.
The code will need to be able to search for letters & numbers
Below is the code for the Click To Transfer Button.
I would like a code so upon pressing Click To Transfer it should check first that the customers name does not exist.
If the name does not exist then let the data be saved on the sheet.
Should there be a customers name of which is the same then i need to see a msgbox advising me of this.
Some info for you.
Worksheet is called POSTAGE
Customers name on worksheet will always be in column B
Range on worksheet is B8 & onwards.
The code will need to be able to search for letters & numbers
Below is the code for the Click To Transfer Button.
Code:
Private Sub CommandButton1_Click()Cancel = 0
If TextBox2.Text = "" Then
Cancel = 1
MsgBox "Customer not entered"
TextBox2.SetFocus
ElseIf TextBox3.Text = "" Then
Cancel = 1
MsgBox "Item Not Entered"
TextBox3.SetFocus
ElseIf TextBox4.Text = "" Then
Cancel = 1
MsgBox "Tracking Not Entered"
TextBox4.SetFocus
ElseIf TextBox5.Text = "" Then
Cancel = 1
MsgBox "Username Not Selected"
TextBox5.SetFocus
ElseIf OptionButton1.Value = False And OptionButton2.Value = False And OptionButton3.Value = False Then
Cancel = 1
MsgBox "Select Origin"
ElseIf OptionButton4.Value = False And OptionButton5.Value = False And OptionButton6.Value = False Then
Cancel = 1
MsgBox "Select An Ebay Account"
End If
If Cancel = 1 Then
MsgBox "Not All Have Been Answered"
Exit Sub
End If
Dim i As Long
Dim x As Long
Dim ctrl As Control
Dim lastrow As Long
lastrow = ThisWorkbook.Worksheets("POSTAGE").Cells(Rows.Count, 1).End(xlUp).Row
With ThisWorkbook.Worksheets("POSTAGE")
.Cells(lastrow + 1, 1).Value = TextBox1.Text: TextBox1.Value = ""
.Cells(lastrow + 1, 2).Value = TextBox2.Text: TextBox2.Value = ""
.Cells(lastrow + 1, 3).Value = TextBox3.Text: TextBox3.Value = ""
.Cells(lastrow + 1, 5).Value = TextBox4.Text: TextBox4.Value = ""
.Cells(lastrow + 1, 9).Value = TextBox5.Text: TextBox5.Value = ""
.Cells(lastrow + 1, 4).Value = TextBox6.Text: TextBox6.Value = ""
If OptionButton1.Value = True Then .Cells(lastrow + 1, 8).Value = "DR": OptionButton1.Value = False
If OptionButton2.Value = True Then .Cells(lastrow + 1, 8).Value = "IVY": OptionButton2.Value = False
If OptionButton3.Value = True Then .Cells(lastrow + 1, 8).Value = "N/A": OptionButton3.Value = False
If OptionButton4.Value = True Then .Cells(lastrow + 1, 6).Value = "EBAY": OptionButton4.Value = False
If OptionButton5.Value = True Then .Cells(lastrow + 1, 6).Value = "WEB SITE": OptionButton5.Value = False
If OptionButton6.Value = True Then .Cells(lastrow + 1, 6).Value = "N/A": OptionButton6.Value = False
End With
TextBox2.SetFocus
TextBox1.Value = Now
TextBox1 = Format(TextBox1.Value, "dd/mm/yyyy")
End Sub
Last edited: