+ Reply to Thread
Results 1 to 3 of 3

Working with Ranges

  1. #1
    Registered User
    Join Date
    09-22-2006
    Posts
    5

    Working with Ranges

    I am trying to get a text box to look at a range of values to determine if what is entered into the text box matches one fo the values in the range of cells. Using the following code I get a type mismatch error message:

    Private Sub TextBox1_Change()
    If TextBox1.Value = Sheet1.Range("A1:A3") Then
    TextBox1.Value = ""
    Exit Sub
    End If

    If I change ("A1:A3") to ("A1") it will work...

  2. #2
    Forum Contributor stevebriz's Avatar
    Join Date
    09-07-2006
    Location
    Santiago Chile
    Posts
    389
    you need to something like

    Private Sub TextBox1_Change()
    For each Cell in Range Sheet1.Range("A1:A3")
    If TextBox1.Value = Sheet1.cell.value Then
    Msgbox "Found"
    else
    'TextBox1.Value = ""
    Next cell
    End If
    VBA - The Power Behind the Grid

    Posting a sample of your workbook makes it easier to look at the Issue.

  3. #3
    Registered User
    Join Date
    09-22-2006
    Posts
    5

    Thanks, But

    Thanks, but it is not working. As written, it brings back an error on the For Each Cell Line. If I change that line to:

    For Each Cell In Sheet1.Range("A1:A3"), then it moves past that line, but then I get an error on:

    If TextBox1.Value = Sheet1.Cell.Value Then

    If I change Cell to Cells, then I get another error on another line:

    Next Cell

    IF I move that line to under End If, then I get a type mismatch back up on the

    If TextBox1.Value = Sheet1.Cells.Value Then
    line.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1