+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Valued Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2007
    Posts
    332

    Find value within (and only within) a range

    Hi - haven't been able to find much on this ... but I'm sure one of you smart people know

    In vba code, how can I restrict my "find" to a given range?

    I'm dynamically building the range (anywhere from 5 - 100 cells in column B on my spreadsheet) and need to see if two values are present anywhere in that range. There will be multiple "ranges" to search, all in a single column.

    I suppose I could loop through each range, but am trying to avoid extraneous loops if there's a better way to do it.

    Thanks for any help!
    Last edited by JP Romano; 01-08-2010 at 02:24 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    05-15-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    797

    Re: Find value within (and only within) a range

    try
    Code:
    Sub FindRng()
    Dim Fnd As String
    Dim Rng As Range
    Fnd = "2"
        With Sheets("Sheet1").Range("A1:A10,A20:A30")
            Set Rng = .Find(What:=Fnd, _
                        After:=.Cells(.Cells.Count), _
                        LookIn:=xlValues, _
                        LookAt:=xlWhole, _
                        SearchOrder:=xlByRows, _
                        SearchDirection:=xlNext, _
                        MatchCase:=False)
            If Not Rng Is Nothing Then
                Application.Goto Rng, True
            Else
                MsgBox "Nothing found"
            End If
        End With
    End Sub
    cheers


  3. #3
    Valued Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2007
    Posts
    332

    Re: Find value within (and only within) a range

    Thanks...that surely did it!

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0