+ Reply to Thread
Results 1 to 5 of 5

Setting a search range to whatever the active sheet is

  1. #1
    Registered User
    Join Date
    02-15-2018
    Location
    Raleigh, NC
    MS-Off Ver
    Excel 2013
    Posts
    12

    Setting a search range to whatever the active sheet is

    I am making a search userform that looks at a specified column in the active worksheet and returns the values within that row.

    It works great on the first sheet (I originally had it searching just one worksheet so I was able to specify that specific sheet). But I wanted to make one generic userform for the entire workbook. Simply put I want the userform to search within whatever worksheet the button that activates the form (i.e. If the button is pressed in Sheet1 it should search within sheet1). I am getting an error with setting the search range.


    My current idea for this was to set the active worksheet upon userform initialization. Here is the code:

    Private Sub UserForm_Initialize()

    Dim Active As Worksheet
    Set Active = ThisWorkbook.ActiveSheet

    End Sub

    The user types in what they are searching for and presses search. Here is the search command button code:

    Private Sub cmdsearch_Click()
    Dim Search As String
    Dim FoundCell As Range, SearchRange As Range

    'This is where I am getting the error (Subscript Out Of Range). I know it has something to do with the active worksheet. '
    'This is what I have now. I have tried just doing Active.Column(4) and ActiveSheet.Column(4) as well'
    Set SearchRange = Worksheets("Active").Column(4)


    Search = Me.txtfind.Text

    If Len(Search) = 0 Then Exit Sub

    Set FoundCell = SearchRange.Find(What:=Search, LookIn:=xlValues, LookAt:=xlPart _
    , SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    If Not FoundCell Is Nothing Then
    Me.txtticket.Text = FoundCell.value
    Me.txtproject.Text = FoundCell.Offset(0, 1).value
    Me.txtdate.value = FoundCell.Offset(0, 2).value
    Me.txttube.value = FoundCell.Offset(0, -1).value
    Else

    MsgBox Search & Chr(10) & "Ticket ID Not Found", 48, "Not Found"
    End If
    End Sub


    It's early in the morning and maybe I'm just not thinking clearly.
    Last edited by dhoyle19; 03-26-2018 at 10:21 AM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Setting a search range to whatever the active sheet is

    Try this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    02-15-2018
    Location
    Raleigh, NC
    MS-Off Ver
    Excel 2013
    Posts
    12

    Re: Setting a search range to whatever the active sheet is

    Norie, I have tried that as well but get an error when I do.

    Runtime error 438: Object does not support this method or property

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Setting a search range to whatever the active sheet is

    You definitely used Columns when you got that error?

  5. #5
    Registered User
    Join Date
    02-15-2018
    Location
    Raleigh, NC
    MS-Off Ver
    Excel 2013
    Posts
    12

    Re: Setting a search range to whatever the active sheet is

    I definitely DIDN'T. That was it. Sorry for being blind. You rock!

    Thanks for the help and bearing with my poor attention to detail on a Monday morning.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. search non active sheet
    By mjwakema in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-21-2017, 07:52 AM
  2. Search for tab in another workbook, name of tab in in a cell in active sheet
    By Excel_101_Stater in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-13-2017, 09:07 PM
  3. Update table on another sheet with information on ACTIVE SHEET based on column search.
    By keelinglee in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-14-2014, 09:06 PM
  4. Search Range for matching value return and to active cell.
    By morbdetro in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-02-2013, 03:08 PM
  5. [SOLVED] Subscript out of range (error 9) When setting active workbook
    By DotWFM in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-11-2013, 04:00 PM
  6. Setting a range in non-active workbook
    By kingdt in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-11-2010, 05:51 AM
  7. setting search range from VBA
    By Ian in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-11-2006, 01:40 PM

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