+ Reply to Thread
Results 1 to 5 of 5

search non active sheet

  1. #1
    Registered User
    Join Date
    08-19-2013
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    27

    search non active sheet

    Good Afternoon,

    I have this code
    Set target = Sheets("Database").Cells.Find(What:=EmNum, After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False)

    and it is working fine if I want to search an the entire sheet, but I would only like to search 3 columns J-N. I change the above code to this

    Set target = Sheets("Database").Columns ("J:N.Find(What:=EmNum, After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False)

    I also tried this

    Set target = Sheets("Database").Range ("J1:N1000").Find(What:=EmNum, After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False)

    neither would find the number I was looking for. The first one does. For example I was searching for N12698. The first code finds it but if I try to just narrow into the 3 columns the target variable comes back as empty.

    I would appreciate any thoughts anyone would have on this.

    Thank you

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: search non active sheet

    What happens if you leave the After:=ActiveCell out?

    If that doesn't work, try to record a macro where you start your macro on another sheet, go to the sheet you want to search and select J:N and search. When it finds what you want, stop the record and look what VBA thought you did.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    08-19-2013
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: search non active sheet

    Thanks for the reply. I tried it without the After:=ActiveCell and this did not make a difference. The problem with you second suggestion is that the macro would record it as a selection on an active sheet. it would look something like this

    Columns("L:N").Select

    I cannot use a select command on a non active sheet.

    again, thank you for the response. it was a good thought!

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: search non active sheet

    OK,

    I've had this same problem. You need to "Fully Qualify" what you are selecting.

    Instead of
    Please Login or Register  to view this content.
    you need to do a
    Worksheets("Sheet Name").Columns...

    This always throws me off.

    If that doesn't work then you need to
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-19-2013
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: search non active sheet

    Marvin,

    Thank you for the reply. I am confused though. I am using worksheets("database") in my code and not just columns.select. Additionally, I do not believe I can even use the .select command as this is a non active sheet and to select something the sheet needs to be activated.
    My goal in this is to search just columns J:N on the database sheet and nothing else on this non active sheet. I apologize if I did not make this clear. The iteration of the code I posted works, but it searches the entire database sheet and not just columns J:N.

+ 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 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
  2. 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
  3. [SOLVED] save active sheet in new workbook, naming it as cell value of active sheet
    By arkharova.s in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-18-2014, 06:16 AM
  4. [SOLVED] Why wont my search function work when i change it from all sheets to active sheet?
    By joshnathan in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-03-2012, 12:58 PM
  5. Search for Value in Closed Workbook and copy Column to Active Sheet Column BE
    By Winon in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-19-2011, 12:57 PM
  6. Copy from active sheet and paste into new sheet using info from cell in active
    By Ingve in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-23-2006, 06:00 PM
  7. create a form for search text in active sheet then got to selected
    By toe in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-08-2005, 10:10 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