Solved

use vb (not VBA) to search EXCEL Cells

Posted on 2007-11-13
8
253 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
  • 4
  • 4
8 Comments
 
LVL 47

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 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 400 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 47

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 47

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now