Checking user input from userform to values in worksheet

Darmlucht

New Member
Joined
Nov 23, 2017
Messages
26
Hi Excel-masters,

I am new to this forum, and I read the rules, but please inform me when I'm not abiding to those rules.
Also, I looked into the forum for previous, related questions, but couldn't find one. But if I missed a thread that's already answering my question, please excuse me.

So here it goes,

I have this userform where the user should fill in their UserId(unique), and ItemId(item they want to rent/check out). Then the date of today and the date they have to return this object, are generated automatic if they puch the button. The data is then posted on a protected sheet, to store all the events.

Now, I want to check the UserId the user filled in, with a list of 'registered users'.
But, for the love of god, I can't find a good piece of code for this.

My code looks like this now:
Code:
Private Sub Uitleen_Click()
    
    ThisWorkbook.Sheets("Uitleen").Unprotect Password:="Jeroen"

    
     UitleenDate.Value = "" & Date
     DateBack.Value = "" & DateAdd("d", 14, Date)
     
    

    Worksheets("Uitleen").Activate
    eRow = Blad7.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    Cells(eRow, 1) = UserID.Text
    Cells(eRow, 2) = ItemID.Text
    Cells(eRow, 3) = UitleenDate.Text
    Cells(eRow, 4) = DateBack.Text
    
       ThisWorkbook.Sheets("Uitleen").Protect Password:="Jeroen"
       
End Sub

I have to check the UserId.Text-input with all the values in the 'User' worksheet, before the data is plotted in the worksheet.
If it's not in the list, there should be an error.
If it is in the list, it should check the ItemId.Text, with the values in the 'Items' worksheet.
The amount of users/items is not fixed, meaning there can be users/items added in the future, but they still have to be included in the checking. So if on day 1 I only have 2 users/items, it should only check from cell A:2 to A:3, but after day2 there are 5 users/items, so it should check from A:2 to A:6.. so the range is not pre-defined.


Is my question clear? If not, please let me know, and I'll try to explain better.
If I have to upload my whole workbook, let me know!

Kind regards, and thanks in advance.
 
****it, again, I posted too soon!
I just noticed I'm 'barking at the wrong tree'!
UsrFnd is set as a range, and I need to check if the user input in UserID.Text is empty, not the range!
So sorry for all my posts that figured out myself a few moments after..
So I changed it now to this:
Code:
If UsrFnd Is Nothing Or UserID.Text = "" Then

        MsgBox "UserId not found"
        ThisWorkbook.Sheets("Uitleen").Protect Password:="Jeroen"
            Exit Sub
          End If
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,221,418
Messages
6,159,793
Members
451,589
Latest member
Harold14

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