Hi, I am New to VBA, when I write a code I meet some question, and I hope someone can help me.
I was trying to use userform to insert a row when condition meets that textbox2 not equal to Range("B") in Master Data worksheet and when range("G") in Master Data worksheet is not equal to zero
But I have problems that how can I insert when condition meets I state above and it can key in the data to the new row.
I was trying to use userform to insert a row when condition meets that textbox2 not equal to Range("B") in Master Data worksheet and when range("G") in Master Data worksheet is not equal to zero
But I have problems that how can I insert when condition meets I state above and it can key in the data to the new row.
Private Sub CommandButton1_Click()
Set mcsh = Sheets("Master Data")
Set msish = Sheets("Stock In")
mclr = mcsh.Range("a65535").End(xlUp).Row
msilr = msish.Range("a65535").End(xlUp).Row
msish.Cells(msilr + 1, "A") = TextBox1
msish.Cells(msilr + 1, "B") = TextBox2
msish.Cells(msilr + 1, "E") = TextBox5
For i = 7 To mclr
If mcsh.Cells(i, "B") & "" = TextBox1 And mcsh.Cells(i, "I") & "" = TextBox2 Then
mcsh.Cells(i, "E") = TextBox5
Set rg = mcsh.Range("C" & i & ":D" & i)
rg.Copy msish.Range("B" & (msilr + 1))
Exit For
End If
If mcsh.Cells(i, "B") & "" = TextBox1 And mcsh.Cells(i, "I") & "" <> TextBox2 And mcsh.Cells(i, "G") = 0 Then
mcsh.Cells(i, "C") = TextBox3
mcsh.Cells(i, "D") = TextBox4
mcsh.Cells(i, "G") = TextBox5
msish.Cells(msilr + 1, "C") = TextBox3
msish.Cells(msilr + 1, "D") = TextBox4
End If
If mcsh.Cells(i, "B") & "" = TextBox1 And mcsh.Cells(i, "I") & "" <> TextBox2 And mcsh.Cells(i, "G") <> 0 Then
mcsh.ActiveCell.EntireRow.Insert
mcsh.Cells(i, "C").Offset(1, 0) = TextBox3
mcsh.Cells(i, "D").Offset(1, 0) = TextBox4
mcsh.Cells(i, "G").Offset(1, 0) = TextBox5
msish.Cells(msilr + 1, "C") = TextBox3
msish.Cells(msilr + 1, "D") = TextBox4
End If
Next
Unload UserForm2
End Sub