+ Reply to Thread
Results 1 to 3 of 3

Set a search area (without selecting it)

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-12-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2007
    Posts
    275

    Set a search area (without selecting it)

    Is is possible to set a search area on a different selection/sheet/workbook without leaving the current selection or leave the current sheet?

    I want to use it in conjunction with the
        Set rngFound = Cells.Find(What:=txbNumber, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
            
            If Not rngFound Is Nothing Then
    
    ...........
    Thanks

  2. #2
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Set a search area (without selecting it)

    Yes, you can. Check the attached code for a demonstration

    Public Sub TestKeepingActiveCell()
    '# declare
         Dim rngSearch As Excel.Range
         Dim rngFound As Excel.Range
    '# set range to search
         Set rngSearch = ThisWorkbook.Worksheets("Sheet2").Range("A1:Z99")
    '# show active cell
         MsgBox "the active cell is " & ActiveCell.Address & " on " & ActiveSheet.Name
    '# execute search
         Set rngFound = rngSearch.Find(What:="abc")
         If rngFound Is Nothing Then
              MsgBox "nothing found"
         End If
    '# show the active cell
         MsgBox "the active cell is " & ActiveCell.Address & " on " & ActiveSheet.Name
    End Sub
    If you like my contribution click the star icon!

  3. #3
    Forum Contributor
    Join Date
    02-12-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2007
    Posts
    275

    Re: Set a search area (without selecting it)

    Thanks Ollie B

    Your answer did give me good guidance. The parameters in my original line does not work with the "rngSearch" spesification.

    Thanks again

+ Reply to Thread

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.6.0 RC 1