+ Reply to Thread
Results 1 to 3 of 3

Using the "find" method to locate a cell with a particular value

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-15-2009
    Location
    Herndon, VA
    MS-Off Ver
    Excel 2010
    Posts
    163

    Question Using the "find" method to locate a cell with a particular value

    Starting in cell D10, I want to come over two columns to the left as in offset(0,-2) which puts me in Column B. Within column B there are various values and empty cells. I want to find the cell that shows "TOTAL COSTS" under Column B.

    After locating TOTAL COSTS in Column B, I want to come over 7 columns to the right which puts me in Column I and take the value in that cell in Column I which is on the same row as the cell for TOTAL COSTS. So from TOTAL COSTS it would be offset(0,7).

    I am using an object variable named "c" to represent D10. I tried c.offset(0,-2).find (what:="TOTAL COSTS", xxxx,xxxx,xxxx,xxxx,xxxx). I just can't get the "find" method to work, which would enable me to zero in on the cell containing the text "TOTAL COSTS" which is in the same column (B).

    Any suggestions?
    Last edited by Excel_vba; 12-17-2009 at 05:30 PM. Reason: No need to say "imagine a table."

  2. #2
    Forum Contributor mewingkitty's Avatar
    Join Date
    09-29-2008
    Location
    Fort McMurray, Alberta, Canada
    MS-Off Ver
    Excel 2003
    Posts
    949

    Re: Using the "find" method to locate a cell with a particular value

    You say you want to start in column D, then move 2 columns to the left... I think you're forgetting to explain a step, or why would you not just start in column B?
    =IF(AND(OR(BLONDE,BRUNETTE,REDHEAD),OR(MY PLACE,HER PLACE),ME),BOW-CHICKA-BOW-WOW,ANOTHER NIGHT ON THE INTERNET)

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Using the "find" method to locate a cell with a particular value

    Hello Excel_vba,

    Here is macro that places the value in column "I" into the variable "X" once the string "Total Costs" has been found in column "B".
    Sub FindTest()
    
      Dim RngB As Range
      Dim RngEnd As Range
      Dim TotalCell As Range
      Dim X As Double
      
       'Define the search range from B10 to the last entry in column "B"
        Set RngB = Cells(10, "D")
        Set RngEnd = Cells(Rows.Count, "B").End(xlUp)
        Set RngB = IIf(RngEnd.Row < RngB.Row, RngB, Range(RngB, RngEnd))
        
         'Search column "B" only for the string "Total Costs", case is ignored
          Set TotalCell = RngB.Find("Total Costs", , xlValues, xlWhole, xlByRows, xlNext, False)
          If Not TotalCell Is Nothing Then
             X = TotalCell.Offset(0, 7)
          End If
          
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ 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