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.


  • Try this

    Sub Find_Match()
        Dim TB As String
        TB = Me.TextBox1.Value
        If Application.WorksheetFunction.CountIf(Range("C:C"), TB) > 0 Then
            MsgBox "Found It!"
            Else: MsgBox "Did not find it"
        End If
    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.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!