+ Reply to Thread
Results 1 to 3 of 3

Thread: Find in VBA

  1. #1
    Registered User
    Join Date
    10-02-2011
    Location
    Provo, UT, USA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Find in VBA

    Hello all,

    I am pretty new to VBA, but I am trying to resolve a little issue I am having. I have a web query pulling in and then I want to search the data for several terms and then copy the relative cell to the left as a variable in my code.

    I have tried to use the find method, but I am having a problem with it finding the term within another cell, but not the one I want. EX. Search term: Price: Finds: List Price: I want: Price: How can I teach it to look for cells with and only with the search term in the cell?

    In addition, I have about 20 terms I am looking for, If it can't find the exact term and nothing else, how do I teach it to do the next?

    Thanks a ton!

    Fellhouse

  2. #2
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,276

    Re: Find in VBA

    Hi FellHouse and welcome to the forum. Give the following code a try
    Sub FindPrice()
        Dim oCell As Range
        Dim Ws1 As Worksheet
        Set Ws1 = Worksheets("Sheet1")
        Set oCell = Ws1.Cells.Find("Price", , xlValues, xlWhole)
    End Sub
    Please leave a message after the beep!

  3. #3
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Find in VBA

    or

    Sub FindPrice()
      msgbox Sheets("Sheet1").Cells.Find("Price:", , xlValues, xlWhole).Address
    End Sub
    and

    Sub copy_FindPrice_leftcell_to_F1()
      Sheets("Sheet1").Cells.Find("Price:", , xlValues, xlWhole).offset(,-1).copy sheets("Sheet1").cells(1,6)
    End Sub
    Last edited by snb; 10-02-2011 at 03:52 PM.



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