jammer12001
New Member
- Joined
- Jan 5, 2011
- Messages
- 15
Been searching around for a couple of hours and have not found exactly what I was looking for. I have a user form that can be opened to create a new purchase order. One of the field's (textbox1) needs to be automatically filled with a random 5 digit number (10000/99999) when you open the user form. I currently just use this:
Private Sub UserForm_Initialize()
TextBox1.Value = RandBetween(10000, 99999)
End Sub
The problem is once the workbook has been closed and re open I get double numbers. The purchase orders will be saved to another sheet (PO Data With PO number located in column A) and I was wondering how I could make sure the value did not already exist before it displays it in the box to fill out the purchase order. If it did exist just loop until it gets a value that doesn't? Maybe I'm going about this the wrong way.
I have read a lot about returning guaranteed random numbers but I can't get it to generate correct and return to the textbox automatically when I open the form.
Thanks in advance,
Ben
Private Sub UserForm_Initialize()
TextBox1.Value = RandBetween(10000, 99999)
End Sub
The problem is once the workbook has been closed and re open I get double numbers. The purchase orders will be saved to another sheet (PO Data With PO number located in column A) and I was wondering how I could make sure the value did not already exist before it displays it in the box to fill out the purchase order. If it did exist just loop until it gets a value that doesn't? Maybe I'm going about this the wrong way.
I have read a lot about returning guaranteed random numbers but I can't get it to generate correct and return to the textbox automatically when I open the form.
Thanks in advance,
Ben