[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

use vb (not VBA) to search EXCEL Cells

Posted on 2007-11-13
8
Medium Priority
?
262 Views
Last Modified: 2010-04-16
I am using Visual Basic Express Edition and would like to search an Excel file for a particular Value in a specific cell. Is this possible without getting a brain cramp?
0
Comment
Question by:evault
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 20277720
Hi evault,

Using late binding (ie, no references required)....

        Dim xlApp As Object = CreateObject("Excel.Application")
        Dim xlWB As Object = xlApp.Workbooks.Open("C:\WorkbookPath.xls")
        Dim xlWS As Object = xlWB.Worksheets("Sheet1")
        Dim xlFndCell As Object = xlWS.Cells.Find("the value", , -4163, 1)
        If Not xlFndCell Is Nothing Then
            MsgBox("The value is found in cell " & xlFndCell.Address)
        End If
        xlWB.Close()
        xlApp.Quit()
        xlWS = Nothing
        xlWB = Nothing
        xlApp = Nothing

Regards,

Wayne
0
 
LVL 1

Author Comment

by:evault
ID: 20278067
Wayne,

Awesome. It worked. How about searchnig a specific cell, say E:21 for another 150 pts?
0
 
LVL 48

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 1600 total points
ID: 20278080
evault,

What do you mean searching for a specific cell? It's always in the same place. To get the value from E21, you'd do something like this....

        Dim xlApp As Object = CreateObject("Excel.Application")
        Dim xlWB As Object = xlApp.Workbooks.Open("C:\WorkbookPath.xls")
        Dim xlWS As Object = xlWB.Worksheets("Sheet1")
        MsgBox "The Value od cell E21 is " & xlWS.Range("E21").Value
        xlWB.Close()
        xlApp.Quit()
        xlWS = Nothing
        xlWB = Nothing
        xlApp = Nothing

Wayne
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:evault
ID: 20278116
Wayne,

I am looking through 100s of Excel spreadsheets, searching for a spefiic value in cell E21.
0
 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 20278124
evault,

You'll need to open each of them, and check the value of cell E21 (as I've shown above) versus the value you are looking for.

Wayne
0
 
LVL 1

Author Comment

by:evault
ID: 20278129
Wayne,

If I may be so bold, could you recomend a good book for VB. I have 20+ years as a programmer but almost experience with VB (you may have noticed).
0
 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 20278150
I can't recommend any books, sorry, as I don't use any. My suggestion is to use the F1 key heaps, and ask stacks of questions here on EE.
0
 
LVL 1

Author Comment

by:evault
ID: 20278189
Good enough. I can use your snippet to accomplish what I need. Thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Progress

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question