Results 1 to 2 of 2

Thread: Finding text in excel

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2012
    Posts
    16

    Finding text in excel

    Morning good gentlemen!

    I am trying to find a particular text (stored into a variable) in an excel spreadsheet. Then I need the cell location (B4, F6, etc) to then get the text right beside it. An example:

    I type "Goose" into a textbox and then it searches for "Goose" in the excel file and returns the cell location or range. This word only appears ONCE and is loaded only once in the whole project. With this range I only trim out the letter out and use the number a a reference to the row where the "Goose" text is in.

    I have this but I cant figure out the rest... btw regid is the text in string
    Code:
    xlsWorkBook = xlsApp.Workbooks.Open("C:\filename.xlsx")
            xlsWorkSheet = xlsWorkBook.Sheets("Sheet1")
            Dim r As Excel.Range
            r = xlsWorkSheet.Cells.Find(regid, , _
            Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart, _
            Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, False)
    msgbox("The row is"+left(str(r),1))

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Jun 2012
    Posts
    16

    Re: Finding text in excel

    Found the answer! the range is returned as an address and not a string so i need:

    Code:
    msgbox(r.address)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width