Hi,
I have a nifty little userform designed to retrieve & hold six values in textboxes taken from a worksheet based on an input that the user enters into the first textbox on the form ('uniqueref') which is then searched for in column A. The code is as follows:
Private Sub uniqueref_AfterUpdate()
lastrow = Range("A65536").End(xlUp).Row
findrow = Range("A1:A" & lastrow).Find(uniqueref.Value, Cells(1, 1)).Row
For I = 1 To 6
UserForm1.Controls.Item("TextBox" & CStr(I)).Value = Cells(findrow, I).Value
Next I
End Sub
The userform also has the ability to rewrite any amended values on the form back to the worksheet using:
Private Sub Ok_Click()
For I = 1 To 6
Cells(findrow, I).Value = UserForm1.Controls.Item("TextBox" & CStr(I)).Value
UserForm1.Controls.Item("TextBox" & CStr(I)).Value = ""
Next I
End Sub
This all works well however I want to adapt the code so that:
a) the form will only accept a numeric value in the 'uniqueref' textbox on the userform
b) the form will only accept a value that exists in column A of the workheet
c) if the above occurs, a msgbox will be displayed saying either "must be a number!" or "number does not exist!"
d) also, that the uniqueref field will be cleared and focus reset so that the user can attempt a new (valid) input
I'm guessing I need a Private Sub uniqueref_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) routine but I'm a bit out of my depth here. Can anyone help please?
Thanks in anticipation of assistance.
Bookmarks