Option Explicit
Dim irow As Long
Dim Rng, cl As Range
Dim currentrow As Long
Dim A, b, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z As Single
Private Sub cmdAddRecord_Click()
With Worksheets("Sheet2")
irow = .Range("A1000000").End(xlUp).Row
'Setting the Range in the desired region Is _
Compare Name Text name vs old data
Set Rng = .Range("A1:A" & irow)
'Next use Is For...Next Loop
For Each cl In Rng
'Add record
If Textname.Text = cl.Value Then
MsgBox "Duplicate Data"
'If the Excit sub is omitted, the program _
will continue to add data even _
after the data is duplicated.
Exit Sub
End If
Next cl
.Range("A" & irow + 1).Value = Textname.Text
.Range("B" & irow + 1).Value = Textaddress.Text
.Range("C" & irow + 1).Value = Textidcard.Text
.Range("D" & irow + 1).Value = Texthost.Text
.Range("E" & irow + 1).Value = Textstatus.Text
.Range("F" & irow + 1).Value = Textfather.Text
.Range("G" & irow + 1).Value = Textmother.Text
.Range("H" & irow + 1).Value = Textcondition.Text
.Range("I" & irow + 1).Value = TextTitleDeed.Text
.Range("J" & irow + 1).Value = TextTonnage.Text
.Range("K" & irow + 1).Value = Textland.Text
.Range("L" & irow + 1).Value = Textpage.Text
.Range("M" & irow + 1).Value = Textrai.Text * 400
.Range("N" & irow + 1).Value = Textngan.Text * 100
.Range("O" & irow + 1).Value = Textwah.Text
.Range("P" & irow + 1).Value = Textwa.Text
.Range("Q" & irow + 1).Value = Textrai.Text * 400 + Textngan.Text * 100 + Textwah.Text + Textwa.Text
.Range("R" & irow + 1).Value = Textlandprice.Text
.Range("S" & irow + 1).Value = (Textrai.Text * 400 + Textngan.Text * 100 + Textwah.Text + Textwa.Text) * Textlandprice.Text
.Range("T" & irow + 1).Value = (Textrai.Text * 400 + Textngan.Text * 100 + Textwah.Text + Textwa.Text) * Textlandprice.Text * (0.3 / 100)
End With
End Sub
Private Sub cmdclear_click()
currentrow = 16
Textname = Cells(currentrow, 1)