vb to check if the records is already existing in the worksheet before adding.

Rchad

New Member
Joined
Jul 11, 2016
Messages
3
Hi
this is my first time here. Hope someone could help me with my querries.

I want to create a vb that i will check first if the records is already exist before adding it to the worksheet
If the record already exist it will prompt a message "record already exist"
Then if click Yes it will continue to add
If No return to the worksheet.
All i have is this.

Private sub commandbutton_click()
Dim lastrow as object
Set lastrow = sheet1.range("a65536").end(xlup)
Lastrow.offset (1,0).value = txtdate.text
Lastrow.offset (1,1).value = txtpodate.text
Lastrow.offset (1,2).value = txtprefix.text
Lastrow.offset (1,3).value = txtcurrency.text
Lastrow.offset (1,4).value = txtamount.text
Unload me

End sub

Ty.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try this:

Now this script cannot do this part unless you explain more. Your quote:
"I want to create a vb that i will check first if the records is already exist"

How are we going to know if the record already exist?

Code:
'Private Sub commandbutton_click()
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row + 1

 Cells(Lastrow, 1).Value = txtdate.Text
 Cells(Lastrow, 2).Value = txtpodate.Text
 Cells(Lastrow, 3).Value = txtprefix.Text
 Cells(Lastrow, 4).Value = txtcurrency.Text
 Cells(Lastrow, 5).Value = txtamount.Text
Unload Me

 End Sub
 
Upvote 0
Sorry.. to elaborate
Its a data entry dbase i use userform for entering the details
When i click the add records all the details will be added to worksheet.
Now i want to add a vb macro that when i click the add recors button
It will check first the details in sheet 1 (column E) before it can be added into worksheet.
All the records are added into sheet1

All i have is a vb macro that add the records to sheet1.
 
Upvote 0
I understand what your saying but what do you want to compare?

If you already have 200 records you want to search all 200 records to see if any value entered into column (E) is the same value that is now in "txtamount"

And if that value is found then stop the script and give you a message is that what you want?
 
Upvote 0

Forum statistics

Threads
1,221,813
Messages
6,162,117
Members
451,743
Latest member
matt3388

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