Need to search column on worksheet to see if value from Userform Textbox exists

  • First let me say thank you for any help, Novice here. I have a userform with a textbox that is auto populated with a value which is made up from two numbers from two different columns on the worksheet. The first number is the date stored as Microsoft reference (ie today 10/13/2021, 44482), a "-", and sequence number (01). It is stored in column C on the worksheet in the following format, "44482-01". I need to find out if that value exists in column C of the worksheet. Below is my feeble attempt to try and find a match. I get the response "Did not find it" every time the code runs, even when the value does exist in the column.



    What am I doing wrong?

  • You should have read the Forum Rules by now.. Please read the Forum Rules to understand how the Forum works and why I have added Code Tags to your post


    All VBA code posted in the forum must be wrapped in code tags, which you omitted, including single-line code snippets.Be sure to use them in future posts.


    How to use code tags


    Just highlight all of the code and press the <> in the post menu above button to add the code tags.


    Thanks.

  • Try this


    Code
    1. Sub Find_Match()
    2. Dim TB As String
    3. TB = Me.TextBox1.Value
    4. If Application.WorksheetFunction.CountIf(Range("C:C"), TB) > 0 Then
    5. MsgBox "Found It!"
    6. Else: MsgBox "Did not find it"
    7. End If
    8. End Sub
  • royUK, you're right I do know that. I apologize for the mistake and offer no excuse but to say... My fault and thank you for bringing it to my attention. As always the code you offered works perfectly. Thank you again.

  • Pleased to help.


    Post back if you need further help.


    Visit my web site, http://www.excel-it.com, for more examples and some helpful articles.