andrewc85
06-02-2016, 11:26 PM
Hello,
I have the below code that I am stuck on, and would be appreciative for any help. It works with a listbox on a userform.
For the text that is in red (the If Statement), the script executes the first "then" action (Sheet1.Cells(x, "B").Value = Me.TextBox1.Text but does not execute the following 2 actions. Sheet1.Cells(x, "C").Value = Me.TextBox2.Text and Sheet1.Cells(x, "D").Value = Me.TextBox3.Text
Any help would be very much appreicated.
Andrew
Code:
Private Sub CommandButton1_Click()
Dim erowa As Integer
Dim x As Integer
Dim y As Integer
If Me.TextBox1.Text = "" Or Me.TextBox2.Text = "" Or Me.TextBox3.Text = "" Then
MsgBox "Please Select a Row"
Else
erowa = Application.WorksheetFunction.CountA(Sheet1.Range("A:A"))
For x = 2 To erowa
If Sheet1.Cells(x, "A").Value = Me.TextBox4.Text Then
Sheet1.Cells(x, "B").Value = Me.TextBox1.Text
Sheet1.Cells(x, "C").Value = Me.TextBox2.Text
Sheet1.Cells(x, "D").Value = Me.TextBox3.Text
End If
Next
Me.TextBox1.Text = ""
Me.TextBox2.Text = ""
Me.TextBox3.Text = ""
End If
End Sub
I have the below code that I am stuck on, and would be appreciative for any help. It works with a listbox on a userform.
For the text that is in red (the If Statement), the script executes the first "then" action (Sheet1.Cells(x, "B").Value = Me.TextBox1.Text but does not execute the following 2 actions. Sheet1.Cells(x, "C").Value = Me.TextBox2.Text and Sheet1.Cells(x, "D").Value = Me.TextBox3.Text
Any help would be very much appreicated.
Andrew
Code:
Private Sub CommandButton1_Click()
Dim erowa As Integer
Dim x As Integer
Dim y As Integer
If Me.TextBox1.Text = "" Or Me.TextBox2.Text = "" Or Me.TextBox3.Text = "" Then
MsgBox "Please Select a Row"
Else
erowa = Application.WorksheetFunction.CountA(Sheet1.Range("A:A"))
For x = 2 To erowa
If Sheet1.Cells(x, "A").Value = Me.TextBox4.Text Then
Sheet1.Cells(x, "B").Value = Me.TextBox1.Text
Sheet1.Cells(x, "C").Value = Me.TextBox2.Text
Sheet1.Cells(x, "D").Value = Me.TextBox3.Text
End If
Next
Me.TextBox1.Text = ""
Me.TextBox2.Text = ""
Me.TextBox3.Text = ""
End If
End Sub